python构建父类的初始化方法有多种
class Person:
def __init__(self, name):
self.name = name
self.age = 18
def eat(self):
print(self.name + "正在吃饭...")
class Student(Person):
def __init__(self,name,clazz):
# 调用父类的构造方法(3种实现方式)
# super(Student,self).__init__(name)
# super().__init__(name)
Person.__init__(self,name)
self.clazz = clazz
def study(self):
print(f'我在{self.clazz},我要好好学习!')
s = Student('大宝','一年级3班')
print(s)
s.eat()
s.study()
print(s.age)