Avoiding Mutable Default Arguments in Python

preview_player
Показать описание
From "The Hitchhiker's Guide to Python"

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.
Рекомендации по теме
Комментарии
Автор

This is a great example. I ran into this problem and was happy to see it explained.

AdamDaubauew