class Parent(object):#父类中必须声明继承object,不然无法使用super调用父类方法
def speak(self):#类里面的方法中必须要有一个参数,代表的是对象本身,任意命名,通常使用self
print("speak in parent")
class Child(Parent):
def speak(self):#重写父类方法
print("speak in child")
Parent.speak(self)#调用父类方法,此方式必须传入self
super(Child,self).speak()#调用父类方法,此方式父类必须继承object,super两个参数为类和类的实例,父类方法只有self的时候可以省略
c =Child()#实例化类
c.speak()#调用方法
super(Child,c).speak()#调用被子类重写覆盖的父类方法,注意第二个参数要传入对象