1、super

    2、newinit

    newinit前执行,new类生成实体,init初始化实体参数

    3、MetaClass元类详解

    4、多态

    1. class Person:
    2. def __new__(cls,*args,**kwargs):
    3. print("this is person new")
    4. return object.__new__(cls)
    5. def __init__(self,name,age):
    6. self.name=name
    7. self.age=age
    8. print("this is person init")
    9. def show(self):
    10. print(f"my name is {self.name},my age is {self.age}")
    11. class Student(Person):
    12. def __new__(cls,*args,**kwargs):
    13. print("this is Student new")
    14. return Person.__new__(cls)
    15. def __init__(self,name,age,score):
    16. super().__init__(name,age)
    17. self.score=score
    18. print("this is Student init")
    19. def show(self):
    20. print(f"my name is {self.name},my age is {self.age},my score is {self.score}")
    21. p=Student(name="tom",age=23,score=100)
    22. p.show()