python中一切都是对象,而我们一般创建的类都是type类的对象

#类创建的本质

class Foo:

    def __init__(self):
        self.name = 123

    def f1(self):
        print(self.name)

#解释器的执行过程
"""
1、遇到class Foo ,执行type的__init__方法
2、type的init的方法里面执行以下创建类的操作
obj = Foo()
3、执行obj = Foo()时会先执行type的__call__方法
4、__call__方法里面会执行Foo类的__new__方法
5、在__call__方法里面Foo类的__init__方法
"""

  

相关文章:

  • 2021-07-31
  • 2022-12-23
  • 2021-06-01
  • 2021-05-14
  • 2021-12-27
  • 2021-05-15
  • 2021-12-17
猜你喜欢
  • 2022-01-06
  • 2021-12-27
  • 2021-10-04
  • 2021-08-16
  • 2021-12-02
  • 2022-02-21
  • 2021-08-04
相关资源
相似解决方案