3 ms·
So it's instantiating the dict in the declaration and recycling it between invocations? I wouldn't have expected that either.
by bsimpson 13y ago
So it's instantiating the dict in the declaration and recycling it between invocations? I wouldn't have expected that either.
- chrisdotcode 13y agoRather the dict is bound during "compile" time, and not at each individual invocation (which would be much better, IMO). And during each invocation, it doesn't get re-bound.
- baq 13y agoit can't be, that wouldn't make sense. "def" is no different than "for" or "if".
- bskap 13y ago"def" in Python is an executable statement, not a declaration- it creates a function object that gets bound to the specified name in the local namespace. The defaults are evaluated when the function is created.