Comparing two class types in python

前端 未结 4 2162
时光取名叫无心
时光取名叫无心 2021-02-20 12:07

I have two classes defined in a module classes.py:

class ClassA(object):
    pass

class ClassB(object):
    pass

And in another m

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-20 12:46

    In addition to the other answers :

    Python uses the concept of metaclasses, which are basically "classes of classes". That means, even a Class is an object in Python, which has its own class - accessible using the type in-build function.

    Because ClassA and ClassB are by default instances of the same metaclass, the comparisons return True.

    If you'd like to know more about metaclasses, this SO post is a good start.

提交回复
热议问题