"A Python Sequence (Un)Packing Primer"
summary
Explains that what looks like “multiple return” is actually tuple creation and unpacking, with the subtle rule that the comma makes the tuple and that nested unpacking and the star operator both capture and repack subsequences for assignments and function calls ( and map positional and keyword args). Demonstrates args/kwargs collection, class init forwarding, and the surprising gotcha that a generator is one-use and gets exhausted; confirms behavior by inspecting bytecode with the dis module bytecode disassembler.
AI-written summary · about
chapters (11)
- 0:00Python sequence unpacking
- 2:07Multiple returns in Python
- 4:38Why unpacking matters
- 7:30Nested unpacking
- 10:42Star operator for subsequences
- 12:49Unpacking in function calls
- 14:58Collecting *args and **kwargs
- 17:05Unpacking in inheritance
- 19:58Mental models in Python
- 21:21Debugging unpacking
- 27:01Summary
related talks
21mBecome a Better Pythonista by Abusing List Comprehensions and :=
01h 07mWhat Does It All Really Mean
28mLoop better: a deeper look at iteration in Python
27mPython Oddities Explained
43mSuper Intermediate Python 3
49mSeven Things Every Python Programmer Should Know
02h 18mComprehending comprehensions
19m13 fun facts about Python's return statement for savvy programmers
