A collection of small Python code snippets demonstrating important (and sometimes surprising) behaviors of the language and libraries I use.
-
NixOS users (like me ๐): Simply run
nix-shell
, and youโre ready to explore Pythonโs intricacies. -
Other systems: Use
uv
to configure the project:uv sync
After this, you should be good to go!
Browse the examples/
directory (organized by topic), read the commented code to understand what each script does, and run it with Python. For example:
python examples/threads/sql_alchemy_is_not_thread_safe.py
Happy coding! ๐
- booleans_are_integers - Demonstrates how Python booleans are actually a subtype of integers
- round_is_not_math_round - Shows that Python's default rounding uses banker's rounding (round-to-even) rather than standard mathematical rounding
- default_mutable_args_are_bad - Illustrates unexpected behavior when using mutable data structures as default function arguments
- race_conditions.py - Demonstrates race condition prevention during deque insertion (using a practical example)
- sql_alchemy_session_is_not_thread_safe.py - Shows a race condition that can occur with SQLAlchemy sessions due to their thread-unsafe nature