To demonstrate my question, I have the following code:
class Base(object):
def __init__(self):
self._base = [1,3]
@property
def base(self):
return self._base
gp = Base()
class Parent1(object):
def __init__(self):
self.gp = gp.base
def appendx(self):
self.gp.append(4)
return self.gp
class Parent2(object):
def __init__(self):
self.gp = gp.base
def appendx(self):
self.gp.append(7)
return self.gp
class First(Parent1, Parent2):
def __init__(self):
super(First, self).__init__()
class Second(Parent2, Parent1):
def __init__(self):
super(Second, self).__init__()
f = First()
s = Second()
# [First]
f.appendx()
print "f.gp = %s" %f.gp # f.gp = [1, 3, 4]
print "s.gp = %s" %s.gp # s.gp = [1, 3, 4]
# [Second]
a = s.appendx()
print "f.gp = %s" %f.gp # f.gp = [1, 3, 4, 7]
print "s.gp = %s" %s.gp # s.gp = [1, 3, 4, 7]
print "a = %s" %a # a = [1, 3, 4, 7]
# [Third]
gp.base[0] ="a"
print "f.gp = %s" %f.gp # f.gp = ['a', 3, 4, 7]
print "s.gp = %s" %s.gp # s.gp = ['a', 3, 4, 7]
print "a = %s" %a # a = ['a', 3, 4, 7]
# [Fourth] Confused from here on
a[0] ="b"
print "f.gp = %s" %f.gp # f.gp = ['b', 3, 4, 7]
print "s.gp = %s" %s.gp # s.gp = ['b', 3, 4, 7]
print "a = %s" %a # a = ['b', 3, 4, 7]
print "type(a) = %s" %type(a) # type(a) = <type 'list'>
I can wrap my head around the first three sections, but I just don't understand, why would updating a list update everything else. Some explanation would help.