Difference of class properties vs Instance

6

What is the purpose of creating attributes in the class if I can create in the instance itself?

    
asked by anonymous 23.05.2017 / 05:53

2 answers

5

The idea is to always have the same set of properties for each class that is created, in the case of class properties.

You are free to put the properties you want in your classes, but this will make the object different from the others in the same class.

In Python, having this kind of assignment is not a problem because this feature is part of the philosophy of language. Whatever new property you are putting on the object, the new property does not interfere with the operation of the object as it is defined by the class.

    
23.05.2017 / 06:01
5

A point worth highlighting is the fact that an attribute in the class is shared for all instances, since the attribute in an instance is unique to the instance.

    
23.05.2017 / 06:03