0

I found that can be changed variables of all instances from one instance.

class Example:
    s = 's'
    lst = []

a = Example()    
a.s = 'z'        # change instance variables
a.lst.append(1)  

b = Example()   
print(b.s)  # 's', the class variable of type 'Str' did not changed
print(b.lst)  # '[1]', but class variable  of type 'List' changed

a.lst.append(7)
print(b.lst)  # '[1, 7]', values of all existing instances changing by instance variable

I found it for type "List", but perhaps there is such security issue/feature for other types, too? Or am I confused?

bl79
  • 1,291
  • 1
  • 15
  • 23

0 Answers0