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

后端 未结 4 1077
太阳男子
太阳男子 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:34

    Line

    NewCounter2.count = 5
    

    Creates new instance level attribute of NewCounter2. After that you accessing two different attributes (NewCounter2.count - instance level attr and NewCounter2.__class__.count - class level attr) that's cause 'strange' behaviour'.

提交回复
热议问题