Mutable default arguments in Python: why `__defaults__` bites A Python programming note published September 2, 2026 warns that mutable default arguments persist across calls because function defaults are stored in the __defaults__ attribute, so a function defined as def add1(x=[]) returns [1], then [1, 1], then [1, 1, 1] on successive calls. The example shows add1.__defaults__ holding ([1, 1, 1],), demonstrating that x.append(1) mutates the shared default object rather than creating a fresh list. Mutable default arguments in Python: why defaults bites September 2, 2026 Python Python Because Python functions’ defaults are kept in defaults , avoid mutable defaults: def add1 x= : x.append 1 same as: add1. defaults 0 .append 1 ‼️ return x add1 1 add1 1, 1 add1 1, 1, 1 🤯 add1. defaults 1, 1, 1 , ← Python generator frames: Inspecting locals with gi frame Claude Code always produces something. That’s the hard part. →