a.实例化类

实例化一个类时
	1. 创建一个对象,调用__new__方法,如果没有会调用父类的__new__方法
	2. 调用__init__方法
	3. 返回对象的引用
class Dog(object):
    def __init__(self):
        print("---init方法---")

    def __new__(cls, *args, **kwargs):
        print("---new方法---")

xtq = Dog()

#---------结果---------

    ---new方法---
View Code

相关文章:

  • 2021-05-21
  • 2021-08-11
  • 2021-11-24
  • 2021-05-18
  • 2022-12-23
  • 2021-06-06
  • 2021-07-07
  • 2021-09-26
猜你喜欢
  • 2021-09-01
  • 2022-12-23
  • 2022-12-23
  • 2021-05-15
  • 2021-08-13
  • 2022-12-23
相关资源
相似解决方案