0
Is it possible, somehow in python, to create attributes in a class that is common to all objects? And somehow if it is changed during the execution of the program change to all objects already created? The closest I saw was to directly change the attribute in the class
class Teste:
a = 0
.
>>>b = Teste()
>>>c = Teste()
>>>Teste.a = 10
In this case for both "b" and "c" the value of "a" would be 10 But if I changed the value of "a" to "b" or "c" individually before changing directly in the class, this would not occur. As shown below:
class Teste:
a = 0
.
>>>b = Teste()
>>>c = Teste()
>>>b.a = 5
>>>Teste.a = 10
In this case the value of "a" in "c" would be changed to 10, but the value of "a" in "b" would still be 5 and would not be changed to 10 either. Thank you in advance
And why does it need to be changed by the object? You cannot simply, when changing, change only by the class?
– Costamilam