一切皆对象:类实际上就是一个对象

Person类也是一个对象,那他一定是由一个类实例化得到的,这个类就是元类
type是内置的一个元类,所有的类都是由type实例化得到的
产生类的类叫做元类

class Person:
  def __init__(self,name):
    self.name = name
 	def score(self):
    print('分数是100')
p = Person('nick')

如何找到元类?

class Person:
  def __init__(self,name):
    self.name = name
 	def score(self):
    print('分数是100')
p = Person('nick')
print(type(p))

同理:type类是产生所有类的元类

print(type(dict))
print(type(list))
print(type(str))
print(type(object))
print(type(type))

相关文章:

  • 2022-12-23
  • 2021-07-29
  • 2021-12-28
  • 2021-10-19
  • 2021-11-24
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-04-04
  • 2022-02-27
  • 2021-11-28
  • 2021-10-04
  • 2022-12-23
  • 2022-01-11
相关资源
相似解决方案