スーパークラス

スーパークラスの作り方

https://py.processing.org/reference/super.html

	
class Robot(object):
  def speak(self):
    print("BZZT BOOP BEEP")

class RoboFeline(Robot):
  def speak(self):
    super(RoboFeline, self).speak()
    print("MEOW PURR PURR")

kitty = RoboFeline()
kitty.speak()
# Prints:
# BZZT BOOP BEEP
# MEOW PURR PURR
class Animal(object):
  def __init__(self):
    self.leg_count = 6

class Grasshopper(Animal):
  def __init__(self):
    # call the __init__ method of parent class
    super(Grasshopper, self).__init__()

hopsalot = Grasshopper()
print(hopsalot.leg_count) # Prints 6

コメントする