4 ms·
> Similar to making all your computations in the expressions for default arguments in python Python default arguments are evaluated only once at function defin
by Izkata 4y ago
> Similar to making all your computations in the expressions for default arguments in python
Python default arguments are evaluated only once at function definition, not every function call. It's the source of one interesting WTF for anyone who assumes otherwise:
def foo(a=[]):
a.append(1)
return a
>>> foo()
[1]
>>> foo()
[1, 1]
>>> foo()
[1, 1, 1]