草庐IT

NewCounter

全部标签

python - python中的属性 "__class__"到底是什么

我有一个关于python中的__class__的问题。文档说__class__是类实例所属的类。于是我进行了一系列的实验:classcounter:count=0def__init__(self):self.__class__.count+=1NewCounter1=counter()printNewCounter1.count#Theresultis1NewCounter2=counter()printNewCounter2.count#Theresultis2printNewCounter2.__class__.countisNewCounter2.count#result:Tru

python - python中的属性 "__class__"到底是什么

我有一个关于python中的__class__的问题。文档说__class__是类实例所属的类。于是我进行了一系列的实验:classcounter:count=0def__init__(self):self.__class__.count+=1NewCounter1=counter()printNewCounter1.count#Theresultis1NewCounter2=counter()printNewCounter2.count#Theresultis2printNewCounter2.__class__.countisNewCounter2.count#result:Tru