0
Difference between instance and class attributes
I'm trying to learn about the instance and class attributes in python. Then am a little confused: is this_obj.var an instance attribute or it belongs to the class attribute. The code is below class Myclass (object): var = 10 this_obj = Myclass() this_obj.somevar = 12 that_obj = Myclass() that_obj.somevar = 12
2 Respostas
+ 3
Instance attributes are owned by the specific instances of a class. This means for two different instances the instance attributes are usually different.
Class attributes are attributes which are owned by the class itself. They will be shared by all the instances of the class.
+ 2
this_obj and that_obj are instances