1、super
2、new 和init
new在init前执行,new类生成实体,init初始化实体参数
3、MetaClass元类详解
4、多态
class Person:
def __new__(cls,*args,**kwargs):
print("this is person new")
return object.__new__(cls)
def __init__(self,name,age):
self.name=name
self.age=age
print("this is person init")
def show(self):
print(f"my name is {self.name},my age is {self.age}")
class Student(Person):
def __new__(cls,*args,**kwargs):
print("this is Student new")
return Person.__new__(cls)
def __init__(self,name,age,score):
super().__init__(name,age)
self.score=score
print("this is Student init")
def show(self):
print(f"my name is {self.name},my age is {self.age},my score is {self.score}")
p=Student(name="tom",age=23,score=100)
p.show()