class Person:
def __init(self,name,age):
print("创建Person")
self.name=name
self.age=age
def say_age(self):
print("{0}的年龄是{1}".format(self.name,self.age))
class Student(Person):
def __init__(self,name,age,score):
#调用父类构造方法,可以使用如下两种方式:
super(Student,self).__init__(name,age)
#法2Person.__init__(self,name,age)
print("创建Student")
self.score=score
s1=Student("高琪",18,90)
s1.say_age()
print(dir(s1))
Traceback (most recent call last):
File "C:\Users\13238\PycharmProjects\pythonProject\pythonProject\81.py", line 16, in <module>
s1=Student("高琪",18,90)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\13238\PycharmProjects\pythonProject\pythonProject\81.py", line 12, in __init__
super(Student,self).__init__(name,age)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)