The trap is only a trap if it's accidental. Python developers sometimes intentionally exploit this unique memory behavior to build memoization systems (caches).
Because a mutable dictionary persists across function executions, you can pass an empty dict as a default parameter to cache expensive calculations directly inside the function without needing global variables.
Loading…