diff options
author | Roman Garanin <evilkhaoskat@gmail.com> | 2018-12-19 22:09:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-19 22:09:29 +0300 |
commit | 7bdc3d8f2f256c4ab704226e392948cad2a0ff13 (patch) | |
tree | 607b4e3633e566dd378e4fc4c0af0f5e530c71a7 | |
parent | d5b09d5b13f2dcb29b812c6b55011ab8bab8d1be (diff) |
[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.
-rw-r--r-- | python3.html.markdown | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/python3.html.markdown b/python3.html.markdown index 4d5bb3ae..795d9e99 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -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 |