Would you like me to teach you how to write Python 🐍 code that is more elegant, more effective, and more expressive than what you have been writing until now... for free?

I am looking to teach Python to people who want to master Python to the best of their abilities.
Do you? If you do, then I know I can help you improve your skills.

How do I know that?

My book has over 10,000 readers, and all of them have one thing in common: they are humans.
Python has dozens of built-ins, and all of them have multiple usage patterns. No human knows all of them by heart, but my research bundled them up nicely in a book for you to reference and learn from.
With the help of the +20 chapters and +260 pages of this book, you will learn more about all the built-ins and their usage patterns, and your code will become more elegant, it will become more effective, and it will also become more expressive.
So... I know what you are thinking! I do!
If the book is so good, why is it free?

Well, my friend Patrick @python_engineer says

[...] you should start charging for it [the book] ;)

Here's a screenshot of the Twitter message he sent me πŸ‘‡
I don't mind telling you the personal reason that drove me to publishing this book for free, forever.

But first, let me tell you how this book will help you level up your Python 🐍 game.
Each chapter focuses on a single concept.

First, I tell you what you are about to learn.

This creates expectations for you and makes you more aware of what I want you to pick up, making it easier for you to pick it up.
After telling you what I'll be talking about... I talk about. I explain everything there is to explain, and I make sure to show you code snippets that help you digest everything.
But, most important of all, I do something that no one else does:

I include examples of real Python code that I took from real Python projects.
Finally, I conclude each chapter with a bullet point list with everything you learned in that chapter.

That list helps make sure you did not miss a single thing and can also be used as a quick reference for later.
All things considered, the book contains roughly 200 actionable Python insights for you.

If you don't want to miss any of those, there's only one thing to do. Download the book for free right here, right now πŸ‘‡

gum.co/pydonts
Oh, how could I forget?!

There are still some hours left in this really cool bundle that I put together with @tw_lgiordani, @learn_byexample, and @driscollis.

Until the end of Halloween, you can get my book + 4 other books for free with this link:

leanpub.com/b/theindiepyth…

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Rodrigo πŸπŸ“

Rodrigo πŸπŸ“ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mathsppblog

1 Nov
Here is a Python 🐍 function that tells you if the input number is even or odd...

But how does it work? πŸ‘‡

It looks a bit weird, doesn't it?

Someone DM'd me this function from a @realpython article, and now this ⚑🧡 will break it down for you.

Here we go πŸš€ Image
If you have heard of Boolean short-circuiting, that's the short answer:

Boolean short-circuiting is what's responsible for the behaviour of `f`.

Let me explain...

First, we need to understand the precedence of the `and` and `or`.

Let me add parentheses πŸ‘‡ Image
`and` has higher precedence than `or`.

In other words, `and` β€œbinds tighter” to its operands than `or`.

Now, usually we use `and` and `or` with Boolean operands, to return a Boolean value.

However, `and`/`or` work with arbitrary objects as operands.

We call it,
Read 14 tweets
30 Oct
πŸπŸ”¦ Python under the hood.

πŸ‘‡πŸ§΅ Here's a thread on the dunder method `__init__`.

You can't say you **know** Python if you don't know this, so...

In this thread we will cover the dunder method `__init__` and its role in Python OOP.

Here we go πŸš€
β€œinit” is short for β€œinitialise” or β€œinitialisation”.

That, right there, tells you what `__init__` is for!

When you create a new instance of a class, you use the method `__init__` to initialise it:

In other words, you use `__init__` to customise the instance.
Here's an example for you.

Say you want to create a class that represents people.

People have names, right? And whenever you create a new person, you want to give them their name.

It will be the __init__'s job, then, to take that name and associate it with the person object.
Read 15 tweets
30 Oct
Want to improve πŸ“ˆ your Python 🐍?

Then STOP πŸ›‘ doing this:

❌ Don't write `for i in range(len(something))`!

βœ… Use `zip` and/or `enumerate`.

You rarely need to iterate over the range of the length of something.

To level up your Python, learn about `zip` and `enumerate`!
In a nutshell, `enumerate` is useful when you need the elements of an iterable *and* the indices as well.

Here is a thread that teaches you the ins and outs of `enumerate`:

In a nutshell, `zip` is useful when you need to iterate over 2 or more iterables *at the same time*.

I also wrote a killer thread about the ins and outs of `zip` a while ago:

Read 4 tweets
30 Oct
I challenged you πŸ†...

You delivered πŸ’ͺ!

I asked you to implement the sum function in Python 🐍.

Now I'll go over some alternatives and tell you what I like βœ… and dislike ❌ about them.

I'll also tell you which one I think is the best, most Pythonic ✨ one.

πŸ‘‡
I didn't get many submissions, so this is going to be a short thread.

The first approach you might feel tempted to follow is by using a `for` loop.

Without too much effort, you can write a pretty clean solution πŸ‘‡
What's good about this solution is that, with no extra effort, it supports the β€œoddβ€œ cases that the built-in `sum` already supports.

For example, I've shown that the built-in `sum` can be used to flatten lists.

So can this implementation:
Read 9 tweets
15 Oct
You can use Python 🐍 docstrings to provide usage examples of your functions!

That's useful to your users!

And did you know that you can use those examples to do small automatic tests on your functions? 😱

Let me break down how in a mini thread πŸ‘‡πŸ§΅ Image
First off, we define a simple function.

In this case, we just define a function to return the successor of an integer: Image
Then, we define a basic docstring for the function, in a single line.

However, we also add an example showing how using the function looks like.

Notice that the example looks like the REPL: Image
Read 9 tweets
13 Oct
Python 🐍 docstrings πŸ“ are very important, because they are the first level of documentation of your code.

Docstrings are great because IDEs can often display them, to give you help, when you start using a function.

Here's some advice on how to write them πŸ‘‡πŸ§΅
The first line of a docstring should be a short sentence explaining, in English, what the function does.

Write the docstring as a command, not as a long-winded description of what is going to happen.

Go straight to the point, make that line count!
If the function isn't trivial, you need to write a more complete docstring.

Explain what the arguments do and the return value.

Explain what/when the function raises errors.

Let the user know of any side-effects that might happen.

...

Write all of this after a blank line.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(