What in the world is the attribute “__class__” in python

后端 未结 4 1066
太阳男子
太阳男子 2020-12-05 07:00

I have a question about __class__ in python.

The documentation says that __class__ is the class to which a class instance belongs. So I con

4条回答
  •  感情败类
    2020-12-05 07:19

    This line:

    NewCounter2.__class__.count = 3
    

    changes the static count of counter, but here:

    NewCounter2.count = 5
    

    NewCounter2 now has its own count attribute that hides the static count;
    so that line has no effect on NewCounter1.
    This is also why NewCounter2.__class__.count != NewCounter2.count.

提交回复
热议问题