Avoiding Mutable Default Arguments in Python

Опубликовано: 29 Сентябрь 2024
на канале: kishstats
1,159
21

From "The Hitchhiker's Guide to Python"
https://docs.python-guide.org/writing...

Default argument value is mutable.

Default argument values are `evaluated only once at function definition time`, which means that modifying the default value of the argument will affect all subsequent calls of the function.

IDE's like PyCharm will show warnings when attempting a mutable default argument.