Class properties difference vs Instance

Asked

Viewed 190 times

6

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

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 into your classes, but this will make the object different from the others in the same class.

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

5

One point worth noting is the fact that an attribute in the class is shared for all instances, whereas the attribute in an instance is unique to the instance.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.