class A:
this_is_origina l_variable_only _for_one_inctan ce = 0
def __init__(self, v):
self.this_is_or iginal_variable _only_for_one_i nctance = v
class B:
this_is_common_ for_all_instanc es = []
def __init__(self, v):
self.this_is_co mmon_for_all_in stances.append( v)
----------------
now I can create some instances of B, but all of them have the same
array, why
if I use append for b1.this_is_comm on_for_all_inst ances, the b2, b3
will have been changed that array.
(where bi is instance of B)
but changes on this_is_origina l_variable_only _for_one_inctan ce works
fine
why it does that?
and how create array in class - normal array, "private variable"
this_is_origina l_variable_only _for_one_inctan ce = 0
def __init__(self, v):
self.this_is_or iginal_variable _only_for_one_i nctance = v
class B:
this_is_common_ for_all_instanc es = []
def __init__(self, v):
self.this_is_co mmon_for_all_in stances.append( v)
----------------
now I can create some instances of B, but all of them have the same
array, why
if I use append for b1.this_is_comm on_for_all_inst ances, the b2, b3
will have been changed that array.
(where bi is instance of B)
but changes on this_is_origina l_variable_only _for_one_inctan ce works
fine
why it does that?
and how create array in class - normal array, "private variable"
Comment