Rodrigo ๐Ÿ๐Ÿš€ Profile picture
Take your Python ๐Ÿ skills to the next level ๐Ÿš€!
Aromat Profile picture Niels Rikze Profile picture Craig Bobbin Profile picture Nishant Misra Profile picture 6 subscribed
May 18, 2023 โ€ข 11 tweets โ€ข 4 min read
I know `print` is the first Python ๐Ÿย function you learned! ๐Ÿš€

And yet, you don't know this about `print` ๐Ÿ‘‡ Image What you know for sure is that `print` will take an object and it will print it on the screen.

That's the basic functionality it provides: Image
May 17, 2023 โ€ข 10 tweets โ€ข 4 min read
I'll tell you the story of a person that had the wrong nameโ€ฆ

And how to prevent that in Python ๐Ÿย with properties ๐Ÿš€.

๐Ÿ‘‡ Image John Doe was a regular guy and when he was born, he was inserted into the government's database of people.

They created a new `Person` and added John's details: Image
May 14, 2023 โ€ข 6 tweets โ€ข 2 min read
Opening a file to read/write is a common task in Python ๐Ÿ.

Here is how to do it right! ๐Ÿš€

๐Ÿ‘‡ Image Python has a built-in `open` that takes a file path and opens that file.

Then, you have to specify whether you want to open the file to read, write, or append.

But this isn't half of the story! Image
May 13, 2023 โ€ข 6 tweets โ€ข 2 min read
The Python ๐Ÿย built-in `round` is great. ๐Ÿš€

Here are some tips on it. ๐Ÿ‘‡ Image The purpose of `round` is toโ€ฆ round numbers!

It rounds numbers to the closest integer.

These are some simple examples: Image
May 12, 2023 โ€ข 7 tweets โ€ข 3 min read
Error handling in Python ๐Ÿย made simple. ๐Ÿš€

๐Ÿ‘‡ Image The keyword `try` is used before code that might fail.

So, if you know something can raise an error, you can write it inside a `try` statement: Image
May 11, 2023 โ€ข 13 tweets โ€ข 5 min read
Every Python ๐Ÿย programmer uses the ICPO rule. ๐Ÿš€

Even if you don't know what it is.

Let me tell you what the ICPO rule is and what it does ๐Ÿ‘‡ Image The ICPO rule is what determines how attribute and method lookup work.

More precisely, it is the ICPO rule that tells Python where to look for attributes and methods in your objects.

This is relevant because everything in Python is an object.
May 10, 2023 โ€ข 10 tweets โ€ข 4 min read
If you write Python ๐Ÿย you need to know about `enumerate`.

It is one of those tools you will use every day. ๐Ÿš€

Let me show you how it works ๐Ÿ‘‡ Image The point of `enumerate` is to give you access to indices and elements while you are iterating over something.

Thus, `enumerate` is commonly used inside a `for` loop: Image
May 9, 2023 โ€ข 16 tweets โ€ข 6 min read
Have you mastered Python's ๐Ÿย `zip` built-in?

It is one of the many powerful tools that Python provides us with to supercharge our `for` loops! ๐Ÿš€

Let me teach you all about it ๐Ÿ‘‡ Image If I could only tell you one thing about `zip` is that it's useful when you need to put two sequences together.

Or even three.

Or more!

But usually, you'll use it with just two. Image
Apr 28, 2023 โ€ข 6 tweets โ€ข 2 min read
I've been doing Python ๐Ÿย for +11 years. ๐Ÿš€

Here's a roadmap to learn 6 major topics you can't miss: ๐Ÿ‘‰ Logic (Booleans, operations, De Morgan's laws)
๐Ÿ‘‰ Graphs
๐Ÿ‘‰ Data structures & algorithms
๐Ÿ‘‰ Number bases and modular arithmetic
๐Ÿ‘‰ Divide & conquer strategies
๐Ÿ‘‰ Greedy strategies

These topics give you a very solid foundation of programming.
Apr 27, 2023 โ€ข 9 tweets โ€ข 4 min read
The Python ๐Ÿย module datetime is your best friend if you want to work with dates and times. ๐Ÿš€

Here are some of the cool things it does: Image โฐย My first tip has to do with how to import the module.

The module is called `datetime`.

Inside it, there are names like `date`, `time`, and `datetime`.

So, my suggestion is to always write `import datetime as dt` and that is it. twitter.com/i/web/status/1โ€ฆ Image
Apr 19, 2023 โ€ข 16 tweets โ€ข 6 min read
Most people think you don't need maths to write Python ๐Ÿ code.

They are wrong.

Here is an 1880's tool that will help you write code like never before: ๐Ÿš€ Image This thread uses ideas and examples from the course Logic II by @brilliantorg.

It's such a USEFUL course for programmers because you need logic to write code. ๐Ÿง

I'll show you the connection. ๐Ÿ‘‡

Tell me, have you ever written an if statement with 3+ conditions? Image
Apr 19, 2023 โ€ข 7 tweets โ€ข 3 min read
If you write Python ๐Ÿย decorators you need to know about `functools.wraps`! ๐Ÿš€

If you don't use it, you are doing decorators wrong! ๐Ÿคท Image ๐Ÿ†ย `functools.wraps` is a decorator that you should always use when you write other decorators.

That's just it.

Let me show you WHY you want to use `wraps`.

First, let me show you a simple function ๐Ÿ‘‡ twitter.com/i/web/status/1โ€ฆ Image
Apr 10, 2023 โ€ข 9 tweets โ€ข 4 min read
The Python ๐Ÿย module `pathlib` is amazing.

Learning about it will make you 10x more productive*! ๐Ÿš€

If you want to work with files, you need to know about it!

Let me show 5 of the most useful tools in this module ๐Ÿ‘‡

(*Actual numbers may vary. ๐Ÿคก) Image When using the module `pathlib`, most of the time you will want to use the class `Path`.

That class will let you work with files, paths, and directories, in your operating system.

So, let us get started! Image
Apr 3, 2023 โ€ข 10 tweets โ€ข 3 min read
How do you time your Python ๐Ÿย code?

Many say that Python is slowโ€ฆ ๐ŸŒ

But we'll use the module timeit to show Python can be quite fast! ๐Ÿš€ Image The module timeit provides a function timeit that you can use to time pieces of code.

The simplest use case is to determine what piece of code is faster among a couple of alternatives.

For example, from the 3 options below, which one do you think will be faster? Image
Mar 31, 2023 โ€ข 18 tweets โ€ข 6 min read
Programmers need to use many number bases:

๐Ÿ‘‰ย decimal (the โ€œnormalโ€ base);
๐Ÿ‘‰ย binary (10011001);
ย ๐Ÿ‘‰ hexadecimal (e.g., F8F8F2).

But you don't need advanced maths for them to make sense.

Read this. ๐Ÿ‘‡
You'll wish you had done it sooner. ๐Ÿš€ This whole thread was inspired by a course on @brilliantorg, a platform that teaches from first principles.

They break down concepts into interactive, bite-sized lessons (like the dots above).

But now, I want to show you how to work with number bases in a very intuitive way!
Mar 27, 2023 โ€ข 8 tweets โ€ข 3 min read
Generators are a really cool Python ๐Ÿย tool.

Let me show you why you should bother learning them! ๐Ÿš€

A short thread: ๐Ÿ‘‡ I have a CSV file that lists all โ€œpurchasesโ€ of my free book โ€œPydon'tsโ€.

I want to go over that data to find the people who paid money for the book.

Then, I want to do something with that data.

I could write the code below ๐Ÿ‘‡

But what's an issue with it?
Mar 17, 2023 โ€ข 22 tweets โ€ข 7 min read
Python ๐Ÿย decorators are often considered an โ€œadvancedโ€ topic.

But they don't need to be hard.

Let me explain ๐Ÿ‘‡ย how decorators are an elegant and powerful tool. ๐Ÿš€ Image The first thing you need to understand is WHY decorators matter.

A decorator is a tool that you use to add a feature to another function.

For example, you can add caching to a function with a caching decorator.

But the, why not implement that in the function itself?
Mar 8, 2023 โ€ข 8 tweets โ€ข 4 min read
As a Python ๐Ÿย programmer, I spend my day inside my IDE.

After all, it's my job!

Here are 6 VS Code @code shortcuts that save me HOURS every week. ๐Ÿš€

A thread with video examples. ๐Ÿ‘‡ Image @code Before I start, I will show the key combinations for VS Code, but these actions are common and your IDE is likely to have a similar shortcut.

Let's jump right into this!
Mar 6, 2023 โ€ข 15 tweets โ€ข 3 min read
Every. Single. Programmer. Needs to know how to debug. ๐Ÿšซ๐Ÿž

The problem is that debugging is kind of an art.

Here is a messy thread with tips to become a debugging artist. ๐Ÿ‘‡ First thing I do when I find a bug is read the error message.

Sounds obvious?

Well, maybe. ๐Ÿคท

I read the error message (instead of freaking out) and open the file where the error is.
Mar 4, 2023 โ€ข 6 tweets โ€ข 3 min read
Python ๐Ÿย developers can use `property` to supercharge their classes. ๐Ÿš€

With `property`, you can write attributes that are computed dynamically.

Properties can also be updated dynamically.

Let me show you how in this thread. ๐Ÿ‘‡ The simple example we are going to use is that of a square.

To create a square, we specify its size.

Then, we define the area of the square as a property.
Mar 2, 2023 โ€ข 7 tweets โ€ข 4 min read
Can you create a read-only attribute in Python ๐Ÿ?

Yes, you can! ๐Ÿš€

Well, only sort of.

I will show you how to cheat. ๐Ÿ‘‡ Image Sometimes you want to provide some attributes in a class that shouldn't be modified.

Some languages control this by having:

๐Ÿ‘‰ย getters; and
๐Ÿ‘‰ย setters.

But not Python!

In Python, you cannot prevent the user from doing `john.name = "Charles"`...

Or can you?