3 ms·
There are actual reasons to make it and keep it that way. Easy caching function's results is one. You may want to read this SO thread: http://stackoverflow.com
by bluecalm 13y ago
There are actual reasons to make it and keep it that way. Easy caching function's results is one. You may want to read this SO thread:
http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument http://stackoverflow.com/questions/1132941/least-astonishmen...
- Tloewald 13y agoThe accepted explanation seems wrong to me. Whether or not functions are first class objects or not, the behavior of def is a matter of design choice and in this case the wrong choice has been made. All the rationales are broken -- they're uncommon use cases and perfectly easy to implement without the behavior, i like Python but this is a wart.