【问题标题】:Why the type of a class is <class 'type'>为什么类的类型是 <class 'type'>
【发布时间】:2021-09-24 07:44:33
【问题描述】:

我正在检查 python 中每件事的类型。但是我不明白为什么类的类型是&lt;class 'type'&gt;

class Hello:
    pass


c = Hello
print('type check one: ', type(c))
print('type check two: ', type(Hello))

输出:- 类型检查一: 类型检查二:

【问题讨论】:

    标签: python class types


    【解决方案1】:

    type is a metaclass in Python

    元类只是一个类中的一个类,as explained here

    因为您没有指定c 是什么类型的对象,而是说它只是一个Hello 类,所以Hello 继承自type,因此使其成为type 类。

    【讨论】:

      猜你喜欢
      • 2010-09-26
      • 1970-01-01
      • 2014-09-19
      • 2021-06-16
      • 2019-05-24
      • 2021-07-31
      • 1970-01-01
      • 1970-01-01
      • 2011-04-29
      相关资源
      最近更新 更多