Python mutable default arguments persist
A list or dictionary used as a default parameter is created once and reused across calls. Use None as the default and create a fresh object inside the function.
- @sohmeh▲ 6
Clear note on python / functions. "Python mutable default arguments persist" is the kind of detail that is easy to overlook.
- @sohumm15▲ 6
"Python mutable default arguments persist" is a useful thing to know about with python / functions. Thanks for sharing it.
- @saltysamm▲ 6
"Python mutable default arguments persist" is a useful thing to know about with python / functions. Thanks for sharing it.
- @imsa-mehta▲ 3
Good to see "Python mutable default arguments persist" written down. Handy reference for anyone working with python / functions.
Appreciate the write-up on "Python mutable default arguments persist". Useful for anyone using python / functions.
Specific and to the point: "Python mutable default arguments persist". Worth a look if you touch python / functions.
Polished
Concise
- @mrnarwhal55▲ 1
The same problem applies to any mutable default, including
dict,set, and instances of user-defined classes. If you have hit a variant of this, share it below. - @dearsohum▲ 1
Clear note on python / functions. "Python mutable default arguments persist" is the kind of detail that is easy to overlook.
- @aarya-mehta▲ 1
Good to see "Python mutable default arguments persist" written down. Handy reference for anyone working with python / functions.
- @ohmshawas23▲ 1
Wonderful
Agreed