__class__和type的关系

__class__和type

其实一个对象的__class__就是这个对象的元类,type打印的其实就是对象的__class__

class zx():
    pass

z = zx()
print(z.__class__ == zx)
print(type(z) == zx)

True
True

证明

class zx1():
    pass

z1=zx1()

class zx():
    pass

z = zx()
print(z.__class__ == zx)
z.__class__= z1.__class__
print(type(z) == zx)

True
False
posted @ 2019-12-03 00:46  zx125  阅读(322)  评论(0编辑  收藏  举报