@teachmepython.bsky.social
+ Follow
240
followers
130
following
400
posts
Posts
Media
Videos
Starter Packs
teachmepython.bsky.social
@teachmepython.bsky.social
· 23h
How to upload a file using FTP in
#Python
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 1d
How to convert a CSV file into a dictionary using
#Python
🐍🔥
Technically, DictReader will turn each line of the CSV file into a dictionary, which can be very nice
teachmepython.bsky.social
@teachmepython.bsky.social
· 6d
For me I am excited to see all these new performance-related improvements, as well as the neat REPL enhancements and more helpful error messages.
teachmepython.bsky.social
@teachmepython.bsky.social
· 6d
What's your favorite new feature in the last couple of releases of
#Python
? 🐍🤔
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 6d
Install the latest
#Python
today with uv:
uv python upgrade 3.14
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 6d
#Python
Tricks
Want to read the Python code of the file you are executing?
Add the following to the end of your script and it will output the entire file to stdout:
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 7d
#Python
3.14 is out now!
🐍 - Free-threading
🐍 - Deferred annotations
🐍 - t-strings
🐍 - ZStandard compression
🐍 - Multi-interpreter support
🐍 - JIT compiler included for Windows and MacOS
🐍 - and more!
1
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 8d
#Python
Pop Quiz 🐍❓
What is the output of the following code?
A) Syntax Error
B) Type Error
C) Case A Found!
D)
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 8d
Need to find the most common number in a sequence with
#Python
? 🐍🔥
The collections module has a great class for that!
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 13d
#Python
Pro Tip - How to flatten a list of lists 🐍🔥
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 13d
Stupid
#Python
trick 🐍🤯
Calling a dunder method directly without using name mangling
teachmepython.bsky.social
@teachmepython.bsky.social
· 15d
#Python
Pop Quic 🐍❓
A) {range}
B) (range)
C) [0, 1, 2]
D) (0, 1, 2)
E) {0, 1, 2}
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 16d
I don't use lambdas very often, but they are very handy in
#Python
when you use the built-in sorted() function
By using a lambda, you can do some cool advanced sorting! 🐍🔥
1
1
6
teachmepython.bsky.social
@teachmepython.bsky.social
· 19d
What have you used
#Python
's case statement for? 🐍❓
If you haven't seen it, here's an example:
teachmepython.bsky.social
@teachmepython.bsky.social
· 20d
#Python
Pop Quiz 🐍❓
What will be the output if you run this code?
A) Outer ZeroDivisionError exception caught
B) Error: You divided by zero!
C) Error: You divided by zero! Finally executed
D) Finally executed
E) None of the above
teachmepython.bsky.social
@teachmepython.bsky.social
· 20d
Need to time how long a short snippet of
#python
code takes to run? Use the timeit module! 🐍🔥
You can also use timeit to time functions and imports!
teachmepython.bsky.social
@teachmepython.bsky.social
· 20d
Here's a silly example of a function factory using
#Python
and lambdas
Normally, you wouldn't use lambdas, but you might have a list of functions or a use a generator to return functions or callables.
teachmepython.bsky.social
@teachmepython.bsky.social
· 25d
Here's some ternary fun with
#Python
🐍🔥
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 25d
How to use
#Python
threads to target specific functions as workers
teachmepython.bsky.social
@teachmepython.bsky.social
· 26d
How often do you use the ternary operator in
#Python
?
Here's an example in case you haven't heard of it:
teachmepython.bsky.social
@teachmepython.bsky.social
· 27d
Have you ever used a generator expression in
#Python
? They are similar to a list comprehension except that you get a generator returned.
Check it out:
2
teachmepython.bsky.social
@teachmepython.bsky.social
· 27d
Function overloading in
#Python
using the functools module! 🐍🔥
teachmepython.bsky.social
@teachmepython.bsky.social
· 28d
You can read his whole write-up here:
benkurtovic.com/2014/06/01/...
teachmepython.bsky.social
@teachmepython.bsky.social
· 28d
One of the craziest lambdas I have ever seen in
#Python
🐍🚀
The obfuscated "Hello World" by Ben Kurtovic
1
1
teachmepython.bsky.social
@teachmepython.bsky.social
· 28d
Have you ever used
#Python
's handy ChainMap collection?
You can use ChainMap to combine dictionaries, among other things:
3