Collection of lesser-known python features that you will love (and use).
I code in Python a lot, and from time to time I learn something new that makes me exclaim "Wow! That's cool! I wonder how I didn't know that before!". The goal of this repository is to collect these kind of discoveries.
Although the features collected here may not be widely known, they are supposed to be potentially useful in your day-to-day work (and mine too!). The goal is not to collect tricks or surprising behaviors that make you ask yourself "WTF is going on here?". If this is what you were looking for this is not the right place, but I can recommend you to spend some time on the amazing wtfpython repository.
- Why
functools.partial
may declutter your code Tuples
can be useful for organizing yourimports
- Using
timeit
module for easy timing of small bits of code Type hints
: what are these guys?@
infix operator for matrix multiplication
- Ellipsis
- Semplifying imports
- Argument unpacking
- String f-formatting
- Dictionary comprehensions
- Generator expressions
- Advanced type hints
- ...
-
I know this hidden gem, but it's not mentioned here!
Let's add it then! Feel free open an issue or make a pull request.
-
The thing x that you wrote is wrong.
Thank you for noticing! Although I do my best, I can make mistakes. That's how we learning works. Feel free open an issue and I'll fix it.
-
Why are you doing this?
A number of reasons! First (very selfishly) I wanted to write down some cools things that I learnt during the last years. Second, I have a lot of fun learning new things and teaching is the best way to learn. Then, since I learnt a lot of things on the web, I'm glad if I give something back too!