2019.9.3学习内容及笔记
小结 元类 首先明确python中一切皆对象,那么 类实际上也是对象 例如:现有一个Person类, 现在我们说一切皆对象,类也是对象,那么这个Person也一定是由一个类实例化得到的,这个类,就叫做元类 **type是内置的一个元类,所有的类都是由type实例化的得到 总结:能产生类的类,叫元类 class Person: def __init__(self,name): self.name=name def score(self): print('分数是100') p=Person('nick') #p.score()#分数是100 a=Person #Person是类名 p1=a('tank') #a实例化产生对象p1 print(p1.name) #tank #如何找元类 #print(type(p))#<class '__main__.Person'> #type类是产生所有类的元类 print(type(Person)) #<class 'type'> print(type(dict))#<class 'type'> print(type(list))#<class 'type'> print(type(str))#<class 'type'> print(type(object))#<class 'type'> print(type(type))#<class