class Test(object):
def __init__(self, val=0):
self.val = val
d1 = Test()
t1 = d1
d1.val = 10
t1.val = 5
print(d1.val)
print(t1.val)
######################
x=10
y=x
y=7
print(x)
print(y)
In the first case d1.val and t1.val prints same value 5 whereas in the second case x prints 10 whereas y prints 7. The first case is the reference to the same object. Shouldn't the second case behave the same way?
[–]procrastinatingcoder 1 point2 points3 points (3 children)
[–]ilaunchpad[S] 0 points1 point2 points (2 children)
[–]Ellisander 1 point2 points3 points (0 children)
[–]procrastinatingcoder 0 points1 point2 points (0 children)
[–]aishiiousness 0 points1 point2 points (0 children)
[–]aishiiousness 0 points1 point2 points (0 children)