mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-04 13:57:38 +02:00
Corrections on Python3 page
This commit is contained in:
@@ -790,11 +790,11 @@ class Superhero(Human):
|
|||||||
# This calls the parent class constructor:
|
# This calls the parent class constructor:
|
||||||
super().__init__(name)
|
super().__init__(name)
|
||||||
|
|
||||||
# overload the sing method
|
# override the sing method
|
||||||
def sing(self):
|
def sing(self):
|
||||||
return 'Dun, dun, DUN!'
|
return 'Dun, dun, DUN!'
|
||||||
|
|
||||||
# add an additional class method
|
# add an additional instance method
|
||||||
def boast(self):
|
def boast(self):
|
||||||
for power in self.superpowers:
|
for power in self.superpowers:
|
||||||
print("I wield the power of {pow}!".format(pow=power))
|
print("I wield the power of {pow}!".format(pow=power))
|
||||||
@@ -817,7 +817,7 @@ if __name__ == '__main__':
|
|||||||
# Calls parent method but uses its own class attribute
|
# Calls parent method but uses its own class attribute
|
||||||
print(sup.get_species()) # => Superhuman
|
print(sup.get_species()) # => Superhuman
|
||||||
|
|
||||||
# Calls overloaded method
|
# Calls overridden method
|
||||||
print(sup.sing()) # => Dun, dun, DUN!
|
print(sup.sing()) # => Dun, dun, DUN!
|
||||||
|
|
||||||
# Calls method from Human
|
# Calls method from Human
|
||||||
@@ -901,7 +901,7 @@ if __name__ == '__main__':
|
|||||||
# Calls parent method but uses its own class attribute
|
# Calls parent method but uses its own class attribute
|
||||||
print(sup.get_species()) # => Superhuman
|
print(sup.get_species()) # => Superhuman
|
||||||
|
|
||||||
# Calls overloaded method
|
# Calls overridden method
|
||||||
print(sup.sing()) # => nan nan nan nan nan batman!
|
print(sup.sing()) # => nan nan nan nan nan batman!
|
||||||
|
|
||||||
# Calls method from Human, because inheritance order matters
|
# Calls method from Human, because inheritance order matters
|
||||||
|
Reference in New Issue
Block a user