[python3/en] A note about common gotcha with mutable defaults

A reminder to be aware of using mutable defaults.
Whether it is a real problem or not depends on exact use-case, but an update fully describing that and updating code with copying list, or defaulting with None and conditional initialization, would probably negatively affect readability of the example.
This commit is contained in:
Roman Garanin 2018-12-19 22:09:29 +03:00 committed by GitHub
parent d5b09d5b13
commit 7bdc3d8f2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -805,6 +805,7 @@ class Superhero(Human):
# add additional class attributes:
self.fictional = True
self.movie = movie
# be aware of mutable default values, since defaults are shared
self.superpowers = superpowers
# The "super" function lets you access the parent class's methods