Python by topic
101 posts about Python, organized by topic rather than by date. Each topic links to its full archive, with the most recent posts listed to get you started.
Functions & parameters
9 posts on functions & parameters. Most recent:
- Python parameters primer
- Write better Python functions!
- Become more fluent with Python functions in just 15 weeks
- Function Dissection Lab: Learn how Python functions work by examining their innards
- Improve your Python: WPE A2 (“Functions for beginners”) starts next week!
- Beyond the “hello, world” of Python’s “print” function
- foo(y=y), and similar code that confuses Python newbies
- Five Python function parameters you should know and use
- Python function brain transplants
Objects & classes
11 posts on objects & classes. Most recent:
- Python is vs ==: Object identity and value equality
- The “why” of object-oriented programming (in Python)
- Let’s de-confuse Python objects!
- LEGB? Meet ICPO, Python’s search strategy for attributes
- Master Python objects (and understand how they work)
- A short Python class puzzle
- Python’s objects and classes — a visual guide
- In Python, it’s all about the attributes
- Teaching and acting (or, why I don’t plan to sell recorded classes in the near future)
- Benchmarking old-style and new-style Python classes
- Making Python’s __init__ method magical
Strings & sequences
12 posts on strings & sequences. Most recent:
- Python str.join(): Why it’s a string method, not a list method
- Reverse a string or list in Python with the [::-1] slice
- Python sequences: The shared API of str, list, and tuple
- Quick Python tip: “int” strips strings of whitespace
- Playing with Python strings, lists, and variable names — or, a complex answer to a simple question
- Understanding Python slices
- Python’s str.isdigit vs. str.isnumeric
- Avoiding Windows backslash problems with Python’s raw strings
- Raw strings to the rescue!
- Speedy string concatenation in Python
- The relative speeds of str.format and %
- Teaching an old dog new tricks — or, how I learned to love Python’s str.format, and gave up on %
Lists & tuples
13 posts on lists & tuples. Most recent:
- Python str.join(): Why it’s a string method, not a list method
- Reverse a string or list in Python with the [::-1] slice
- Python sequences: The shared API of str, list, and tuple
- Playing with Python strings, lists, and variable names — or, a complex answer to a simple question
- Why do Python lists let you += a tuple, when you can’t + a tuple?
- Python parentheses primer
- Implementing “zip” with list comprehensions
- Understanding nested list comprehensions in Python
- Sorting lists of dicts — an exercise from “Practice Makes Python”
- Turning a PostgreSQL array to rows
- Turning PostgreSQL rows into arrays
- PostgreSQL array indexes and length
- Good intentions, unexpected results: Mailing lists and DMARC
Dictionaries & sets
7 posts on dictionaries & sets. Most recent:
- Python set subset checks with <=: Spelling Bee word validation
- dict.fromkeys: Why a mutable default value gets shared
- Today’s lesson in “Python for non-programmers”: Dictionaries
- Python dicts and memory usage
- Is it hashable? Fun and games with hashing in Python
- Sorting lists of dicts — an exercise from “Practice Makes Python”
- Creating Python dictionaries with “reduce”
Comprehensions
4 posts on comprehensions. Most recent:
- You can, but should you? Combining some of Python’s more esoteric features
- Implementing “zip” with list comprehensions
- Understanding nested list comprehensions in Python
- Want to understand Python’s comprehensions? Think in Excel or SQL.
Iterators & generators
2 posts on iterators & generators. Most recent:
- Making sense of generators, coroutines, and “yield from” in Python
- A quick introduction to implementing Python iterators
Decorators
3 posts on decorators. Most recent:
- Stop fearing Python decorators
- Making your Python decorators even better, with functool.wraps
- Get code + slides from my “Practical Decorators” talk from Euro Python / PyCon 2019
Map, filter & reduce
10 posts on map, filter & reduce. Most recent:
- Thinking with “map”
- Summary of my “reduce” series
- Implementing “filter” with “reduce”, in Ruby and Python
- Implementing “map” with “reduce”, in Ruby and Python
- Creating Ruby hashes with “reduce”
- Creating Python dictionaries with “reduce”
- Creating collections with “reduce”
- Implementing “min” and “max” with “reduce”
- Calculating Scrabble scores with “reduce”
- Understanding “reduce” (first in a series)
Scoping & namespaces
4 posts on scoping & namespaces. Most recent:
- LEGB? Meet ICPO, Python’s search strategy for attributes
- foo(y=y), and similar code that confuses Python newbies
- 2+2 might be 4, but what is True+True?
- Fun with Python scoping rules
Modules & imports
3 posts on modules & imports. Most recent:
- importlib.reload: Reimporting a Python module during development
- Python import: How a module name becomes a file on sys.path
- Globbing and Python’s “subprocess” module
Exceptions & errors
3 posts on exceptions & errors. Most recent:
- Working with warnings in Python (Or: When is an exception not an exception?)
- My favorite terrible Python error message
- How not to write an error message
More topics
AI-assisted coding
- New: In-browser Python/Pandas/Git exercises, with AI support
- Is Python becoming Pinyin?
- Take agentic coding to the next level
- Learn to code with AI — not just write prompts
- We’re all VCs now: The skills developers need in the AI era
- My Week with ChatGPT
course-setup
Dates & times
Files & I/O
- Python import: How a module name becomes a file on sys.path
- Using Python to delete files based on other files’ names
- If you don’t use “with”, when does Python close files? The answer is: It depends.
Git
- New: In-browser Python/Pandas/Git exercises, with AI support
- Save time — and 30% — with my 25 Python, Git, and data science courses!
- In PostgreSQL, as in life, don’t wait too long to commit
- The easiest way to return to the last Git branch
Identity & equality
Loops & control flow
Numbers & precision
- Python round and banker’s rounding: Why round(2.5) returns 2
- Python numeric literals: Using underscores to group digits
- Understanding bitwise operations in Python
- 2+2 might be 4, but what is True+True?
- Fun with floats
Regular expressions
Shell & developer tools
Syntax & formatting
- Python line continuation: How parentheses split long lines
- You can, but should you? Combining some of Python’s more esoteric features
- Python parentheses primer
