Python class attributes and their initialization

前端 未结 3 507
陌清茗
陌清茗 2021-01-12 21:08

I\'m quite new in python and during these days I\'m exploring classes. I have a question concerning attributes and variables inside classes: What is the difference between d

3条回答
  •  野的像风
    2021-01-12 21:48

    The most significant difference between the q attribute in this classes is that in MyClass1 implementation the variable will be shared across all the instances of this class, while in MyClass2 it's only visible in the scope of this particular object.

    Some docs: https://docs.python.org/2/tutorial/classes.html#class-and-instance-variables

提交回复
热议问题