Pinned Tweet
Mutability often confuses new Python programmers, especially when attempting to create copies of a mutable object.
See the differences below when only referencing an existent mutable object, and when doing shallow and deep copying.
#100DaysOfCode #Python #CodeNewbie #Python3
What a great testing tool for Python is time-machine!
I was able to stretch my tests to many different cases while keeping a clean API.
github.com/adamchainz/time-m…
Kudos to @AdamChainz
Reminder: commit early, commit often.
I had such a mess earlier today due to mixing a lot of things in the same commit, which I had to modify later to drop certain things from there.
If I had made a commit for each step, it would have been a piece of cake.
2
155
I'm learning a new language for the first time in years! Let's see how it is outside Pythonland nowadays...
2
10
My Python Core Language IQ is 259—that’s better than 97% of my peers! What's your #PluralsightIQ? app.pluralsight.com/score/re…
2
I'd like to start revisiting the Itertools Recipes, with one of my favorites:
⏩all_equal(iterable)
As its docstring states, it returns True if all the elements are equal to each other
But how does it do it? 🤔 Let's see!
🧵
2
3
Y'all need to stop using indentation as a way to denote scopes in Python. Nothing like good old curly braces.
Just do:
>>> from __future__ import braces
To start using them in your code.
...
(Thanks to @jamescalam for the great tip)
I loved strftime method, but...
TIL:
I've stopped using datetime.strftime() and just use f-strings. #Python
Did you know that you can do this?
Instead of
>>> somedate.strformat("%Y-%m-%d")
do
>>> F"{somedate:%Y-%m-%d}"
Python Tip Time! 🐍
By adding a slash (/) or an asterisk (*) to your function's parameters, you can force the use of positional-only or keyword-only arguments, respectively.
Take a look:
Python tip🐍
Do you want your objects to be immutable? Since Python 3.7, you can use dataclasses for this!
Just use the @dataclass decorator with the "frozen" keyword argument set to True.
A very easy to understand explanation about the Descriptor Protocol by Josue!
You know what descriptors are in Python?
Descriptors are a protocl that let us specify instance attribute's lookup, storage and deletion from the data's POV
It's like asking Alexa for the weather. It knows where to get the data, you don't, then you yell it at your spouse
2
Python Tip 🐍
Use the __lt__() rich comparison method (i.e: lower than), to allow custom objects to be sorted.
.
.
.
*note: It's a good practice to return the NotImplemented object when defining these kind of methods ;)
#100DaysOfCode #Python
The first line of code I ever wrote was back in 2011.
I remember I used an educational programming language called PSeInt (pseint.sourceforge.net).
I can't stress enough how much it helped me back then to understand the basics of programming.
4
Python tip 🐍
Get the most common element from an iterable (list, tuple, string...) using a Counter object.
#100DaysOfCode #Python
I switched from Windows to Ubuntu 90 days ago, and the only thing that I was missing about Windows was MS Office.
I had been using LibreOffice since I switched, and the experience wasn't good at all.
I installed WPS today, and it's awesome! 🤩
wps.com/
1
5
I've wanted to give @kivyframework a try since a long time.
This weekend I started doing a pomodoro app with it. Let's see how it goes!
1
6
So far, I like the concept behind their Kv language, and .kv files.
It's nice to declare the GUI layout in a CSS-like way, as opposed to other tools such as PyQT or Tkinter.
kivy.org/doc/stable/guide/la…
1
















