class Inventory:
def __init__(self):
self.slots = []
def add_item(self, item):
self.slots.append(item)
class SortedInventory(Inventory):
def add_item(self, item):
super().add_item(item)
a = SortedInventory()
a.add_item(2)
print (a.slots)
class C(B):
def method(self, arg):
super().method(arg) # This does the same thing as:
# super(C, self).method(arg)
class Fish:
class Fish(object):
def __init__(self):
print("In Fish class")
def swim(self):
print("The fish is swimming.")
def swim_backwards(self):
print("The fish can swim backwards.")
class Trout(Fish):
def __init__(self):
print ("In Trout class")
super().__init__() # 写成super().__init__(self) 是错的!会报错!
a = Trout()