Here is a code:
>>> class A(object):
... value = []
... def method(self, new_value):
... self.value.append(new_value)
...
>>> a = A()
>>> a.value
[]
>>> a.method(1)
>>> b = A()
>>> b.value
[1]
>>> b.method(2)
>>> b.value
[1, 2]
>>> a.value
[1, 2]
This happens only with lists. Is the only way to deffine value in __init__?
How to normally define default class values in python?
UPD
thank you for your responses
>>> class B(object):
... value = "str"
... def method(self):
... self.value += "1"
...
>>> a = B()
>>> a.value
'str'
>>> a.method()
>>> a.value
'str1'
>>> b = B()
>>> b.value
'str'
I don't get, why list is shared but str is not?