mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[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:
parent
d5b09d5b13
commit
7bdc3d8f2f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user