#父类:
class Vector:
def __init__(self,x,y):
self.x = x
self.y = y
def demo(self):
print(“This is python.”)
#python2继承:
class Vector2(Vector):
def __init__(self,x,y,z):
Vector.__init__(self,x,y)
self.z = z
def demo(self):
Vector.demo(self)
print(“This is python2.”)
#python3继承:
class Vector3(Vector):
def __init__(self,x,y,z):
super().__init__(x,y)
#super(Vector3,self).__init__(x,y)
self.z = z
def demo(self):
super().demo(self)
print(“This is python3.”)
python2 super(Vector2,self).__init__(x,y) 会报Vector2需要是type类型,所以使用父类名进行继承代替super,以此作为知识点标记。