class A():
def init(self,name,age):
self.name =name
self.age = age
class B(A):
def init(self,name,age):
super().__init__(name,age)
self.score = 0
def say(self):
print("name = %d" % self.name)
print("age = %d" % self.age)
print("score = %s" % self.score)
data = B(1,2)
data.say()
还有这种 :好好看下区别 当然貌似还有继承多个类 我也不太懂
class A():
def init(self,name,age):
self.name =name
self.age = age
def say(self):
print("这是父类")
class B(A):
def init(self,name,age):
A.__init__(self,name,age)
self.score = 0
def say(self):
print("name = %d" % self.name)
print("age = %d" % self.age)
print("score = %s" % self.score)
def extend2(self):
A.say(self)
data = B(1,2)
data.say()
data.extend2()