From 7bdc3d8f2f256c4ab704226e392948cad2a0ff13 Mon Sep 17 00:00:00 2001 From: Roman Garanin Date: Wed, 19 Dec 2018 22:09:29 +0300 Subject: [PATCH] [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. --- python3.html.markdown | 1 + 1 file changed, 1 insertion(+) 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