mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-04-26 23:23:55 +00:00
Merge 7f6d36839e
into 7f0f27d84d
This commit is contained in:
commit
3652bab3c0
@ -856,12 +856,15 @@ class Superhero(Human):
|
|||||||
# This constructor inherits the "name" argument from the "Human" class and
|
# This constructor inherits the "name" argument from the "Human" class and
|
||||||
# adds the "superpower" and "movie" arguments:
|
# adds the "superpower" and "movie" arguments:
|
||||||
def __init__(self, name, movie=False,
|
def __init__(self, name, movie=False,
|
||||||
superpowers=["super strength", "bulletproofing"]):
|
superpowers=None):
|
||||||
|
|
||||||
# add additional class attributes:
|
# add additional class attributes:
|
||||||
self.fictional = True
|
self.fictional = True
|
||||||
self.movie = movie
|
self.movie = movie
|
||||||
# be aware of mutable default values, since defaults are shared
|
# be aware of mutable default values, since defaults are shared
|
||||||
|
if superpowers is None:
|
||||||
|
# assigns default superpowers, but this way new list is created on each initialization.
|
||||||
|
self.superpowers = ["super strength", "bulletproofing"]
|
||||||
|
else:
|
||||||
self.superpowers = superpowers
|
self.superpowers = superpowers
|
||||||
|
|
||||||
# The "super" function lets you access the parent class's methods
|
# The "super" function lets you access the parent class's methods
|
||||||
|
Loading…
Reference in New Issue
Block a user