Rodrigo Girão Serrão 🐍🚀
@mathspp.com
I'll help you take your Python skills to the next level!
Get a daily drop of Python knowledge 🐍💧 -> https://mathspp.com/drops
Pydon'ts – free Python book 👉 https://mathspp.com/books/pydonts
Get a daily drop of Python knowledge 🐍💧 -> https://mathspp.com/drops
Pydon'ts – free Python book 👉 https://mathspp.com/books/pydonts
All Python objects have a Truthy/Falsy value.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
November 10, 2025 at 10:54 AM
All Python objects have a Truthy/Falsy value.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
This is the value of an object when used in a Boolean context.
For example, when used in the condition of an `if` statement.
Most objects are Truthy, with a few exceptions.
For most types, the “nothing” or “empty” value is Falsy.
When building complex readable strings, consider building them out of smaller fragments.
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
November 7, 2025 at 2:25 PM
When building complex readable strings, consider building them out of smaller fragments.
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
The function `oxford_comma`, shown below, demonstrates this technique.
What's the point of the smaller fragments?
Python has a very well-known naming convention:
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
November 6, 2025 at 12:03 PM
Python has a very well-known naming convention:
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
Names that start with a leading underscore are “private”.
This means the outside world has no business using them.
E.g., attributes and methods starting with `_` in a class mean they're for that class only.
The methods `strftime` and `strptime` can be used to convert dates/times into strings and vice-versa.
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
November 5, 2025 at 12:01 PM
The methods `strftime` and `strptime` can be used to convert dates/times into strings and vice-versa.
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
Here's a mnemonic to help you:
👉 `strptime` has a “P” for “Parse date/time”, so string -> date
👉 `strftime` has an “F” for “Format date/time”, so date -> string
The string method `str.split` has a parameter `maxsplit` that determines the maximum number of splits that will be performed.
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
November 4, 2025 at 11:58 AM
The string method `str.split` has a parameter `maxsplit` that determines the maximum number of splits that will be performed.
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
The returned list with the splits (and possibly the remainder of the string) has a maximum length of `maxsplit + 1`.
Hah, you beat me to it.
But I'll do it either way, it's the logical follow-up to my uv cheat sheet.
But I'll do it either way, it's the logical follow-up to my uv cheat sheet.
November 3, 2025 at 2:07 PM
Hah, you beat me to it.
But I'll do it either way, it's the logical follow-up to my uv cheat sheet.
But I'll do it either way, it's the logical follow-up to my uv cheat sheet.
This is your friendly reminder that str.split accepts a parameter to determine the maximum number of splits. You get up to n splits and the remainder of the string.
October 31, 2025 at 1:51 PM
This is your friendly reminder that str.split accepts a parameter to determine the maximum number of splits. You get up to n splits and the remainder of the string.
Live-coding during trainings + automatically syncing to git so everyone has access to what I'm typing =
Very informative git history.
Very informative git history.
October 28, 2025 at 1:00 PM
Live-coding during trainings + automatically syncing to git so everyone has access to what I'm typing =
Very informative git history.
Very informative git history.
Believe it or not, it took me 30+ min and nagging a core dev to get this TINY documentation issue fixed.
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.
October 26, 2025 at 2:40 PM
Believe it or not, it took me 30+ min and nagging a core dev to get this TINY documentation issue fixed.
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.
But at least I'll sleep well tonight, knowing all “See also” call outs are correctly formatted.
I've turned this blog post cheatsheet into a downloadable cheatsheet.
You can get the cheatsheet from here: mathspp.com/blog/uv-chea...
You can get the cheatsheet from here: mathspp.com/blog/uv-chea...
October 10, 2025 at 8:34 AM
I've turned this blog post cheatsheet into a downloadable cheatsheet.
You can get the cheatsheet from here: mathspp.com/blog/uv-chea...
You can get the cheatsheet from here: mathspp.com/blog/uv-chea...
Is this looking good?
(I'm turning my “uv cheatsheet” blog post into an actual cheatsheet you can download.)
(I'm turning my “uv cheatsheet” blog post into an actual cheatsheet you can download.)
September 28, 2025 at 2:02 PM
Is this looking good?
(I'm turning my “uv cheatsheet” blog post into an actual cheatsheet you can download.)
(I'm turning my “uv cheatsheet” blog post into an actual cheatsheet you can download.)
Here's a fun way of counting words in a string in Python.
This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory)
Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory)
Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
September 5, 2025 at 12:51 PM
Here's a fun way of counting words in a string in Python.
This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory)
Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory)
Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
Do you want to create professional-looking projects?
You'll need lots of shiny badges like the one you can see below for my most recent project 👇
You can create custom badges at shields.io, it's a pretty cool service!
Very professional, much wow!
You'll need lots of shiny badges like the one you can see below for my most recent project 👇
You can create custom badges at shields.io, it's a pretty cool service!
Very professional, much wow!
September 3, 2025 at 2:12 PM
Do you want to create professional-looking projects?
You'll need lots of shiny badges like the one you can see below for my most recent project 👇
You can create custom badges at shields.io, it's a pretty cool service!
Very professional, much wow!
You'll need lots of shiny badges like the one you can see below for my most recent project 👇
You can create custom badges at shields.io, it's a pretty cool service!
Very professional, much wow!
It always gets me when I write :D in a GitHub issue and the emoji dropdown suggests a dagger 🤣
September 2, 2025 at 1:53 PM
It always gets me when I write :D in a GitHub issue and the emoji dropdown suggests a dagger 🤣
A good example of what `functools.Placeholder` from Python 3.14 allows.
August 31, 2025 at 3:46 PM
A good example of what `functools.Placeholder` from Python 3.14 allows.
I am now a poet. ✍️
August 28, 2025 at 2:23 PM
I am now a poet. ✍️
I'm working on a Ruff-related video course for @realpython.com ...
As my reviewer noted, my poor (or genius?) choice of directory name makes it look like my terminal is barking all the time 🤣
What do you say?
Poor choice for a directory name or genius move?
As my reviewer noted, my poor (or genius?) choice of directory name makes it look like my terminal is barking all the time 🤣
What do you say?
Poor choice for a directory name or genius move?
August 27, 2025 at 4:56 PM
I'm working on a Ruff-related video course for @realpython.com ...
As my reviewer noted, my poor (or genius?) choice of directory name makes it look like my terminal is barking all the time 🤣
What do you say?
Poor choice for a directory name or genius move?
As my reviewer noted, my poor (or genius?) choice of directory name makes it look like my terminal is barking all the time 🤣
What do you say?
Poor choice for a directory name or genius move?
I just had a couple of minutes of fun writing an infinite binary counter in Python.
However, I thought I'd be able to express this easily with recursion but nothing obvious comes to mind...
Any suggestions?
However, I thought I'd be able to express this easily with recursion but nothing obvious comes to mind...
Any suggestions?
August 21, 2025 at 1:21 PM
I just had a couple of minutes of fun writing an infinite binary counter in Python.
However, I thought I'd be able to express this easily with recursion but nothing obvious comes to mind...
Any suggestions?
However, I thought I'd be able to express this easily with recursion but nothing obvious comes to mind...
Any suggestions?
I've known about Python's `dict.fromkeys` for a while now...
But I only discovered today that you can specify a default value to associate with all keys!
I thought you always had to initialise the dict with all keys mapping to `None`!
But I only discovered today that you can specify a default value to associate with all keys!
I thought you always had to initialise the dict with all keys mapping to `None`!
August 14, 2025 at 2:24 PM
I've known about Python's `dict.fromkeys` for a while now...
But I only discovered today that you can specify a default value to associate with all keys!
I thought you always had to initialise the dict with all keys mapping to `None`!
But I only discovered today that you can specify a default value to associate with all keys!
I thought you always had to initialise the dict with all keys mapping to `None`!
It's been 4 weeks, but it feels like it was yesterday!
EuroPython '25 took place in Prague 🇨🇿 this year and this was the fourth EuroPython I attended.
It was simultaneously the one I enjoyed the most and the one that was the most tiring. 😰
This was also the most rewarding conference for me so far.
EuroPython '25 took place in Prague 🇨🇿 this year and this was the fourth EuroPython I attended.
It was simultaneously the one I enjoyed the most and the one that was the most tiring. 😰
This was also the most rewarding conference for me so far.
August 11, 2025 at 2:32 PM
It's been 4 weeks, but it feels like it was yesterday!
EuroPython '25 took place in Prague 🇨🇿 this year and this was the fourth EuroPython I attended.
It was simultaneously the one I enjoyed the most and the one that was the most tiring. 😰
This was also the most rewarding conference for me so far.
EuroPython '25 took place in Prague 🇨🇿 this year and this was the fourth EuroPython I attended.
It was simultaneously the one I enjoyed the most and the one that was the most tiring. 😰
This was also the most rewarding conference for me so far.
The Python keyword `elif` is a lie!
But they don't want you to know that!
You are welcome.
But they don't want you to know that!
You are welcome.
August 1, 2025 at 3:22 PM
The Python keyword `elif` is a lie!
But they don't want you to know that!
You are welcome.
But they don't want you to know that!
You are welcome.
Who can guess what's coming? 🤔
🇵🇹 ❤️ 🐍
🇵🇹 ❤️ 🐍
July 25, 2025 at 1:23 PM
Who can guess what's coming? 🤔
🇵🇹 ❤️ 🐍
🇵🇹 ❤️ 🐍
PyCon Portugal 🇵🇹 is starting!
(A bit late, but it's starting nonetheless!)
Wish me luck – hopefully no one else cancels their talk last-minute!
P.S. I need an idea for a lightning talk... What do you suggest?
(A bit late, but it's starting nonetheless!)
Wish me luck – hopefully no one else cancels their talk last-minute!
P.S. I need an idea for a lightning talk... What do you suggest?
July 24, 2025 at 8:26 AM
PyCon Portugal 🇵🇹 is starting!
(A bit late, but it's starting nonetheless!)
Wish me luck – hopefully no one else cancels their talk last-minute!
P.S. I need an idea for a lightning talk... What do you suggest?
(A bit late, but it's starting nonetheless!)
Wish me luck – hopefully no one else cancels their talk last-minute!
P.S. I need an idea for a lightning talk... What do you suggest?
Here's a table with the base word “legal” and all combinations of \b & \B around the word.
July 23, 2025 at 12:29 PM
Here's a table with the base word “legal” and all combinations of \b & \B around the word.