Day11 Python面向对象编程学习笔记11(元类)
2020-03-28 20:07
246 查看
我们已经知道在Python里面,万物皆是对象。所以我们用class创建的一个类,在本质上也是一个对象,那么创建这个类对象的类是谁?
num=10 string="abcde" #以上都可以看做是对象 class Person: pass p=Person() #查询一个对象所属的类通过__class__去查询 print(num.__class__) #显示出int print(string.__class__) #显示出str print(p.__class__) #显示出Person #在对int、str和Person查询他们的类 print(int.__class__) print(str.__class__) print(Person.__int__) #都显示出type这个类 #那么type又是谁创建出来的呢? print(type.__class__) #依旧显示出是type
上述实验显示出所有的对象都是由一个叫type的类所创建的(包括type自己),只不过type创建的一些对象有实例化的本领,而有些没有。
对于type我们称他为元类。
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- 深刻理解Python中的元类(metaclass)
- python-day11--函数
- 深刻理解Python中的元类(metaclass)
- 使用Python的元类实现AOP监控类方法调用过程
- python装饰器、类可以用来装饰、元类、type()的使用、python的存储机制:小整数池、intern机制
- Python中的元类(__metaclass__)
- Python天天美味(33) - 五分钟理解元类(Metaclasses)[转]
- 深刻理解Python中的元类(metaclass)
- Python中的元类(metaclass)
- Python中的元类和__metaclass__
- Python——五分钟理解元类(metaclasses)
- 22 Python class 深入理解Python中的元类(metaclass)
- 深刻理解Python中的元类
- 【类】深刻理解Python中的元类(metaclass)
- Python中的元类(译)
- 深刻理解Python中的元类(metaclass)(转)
- python 怎么更好的理解元类
- Python中的元类 -- metaclass
- python中的元类
- python-反射-元类-单例模式