When assigning a variable (or name) in Python, you are creating a reference, have a look at below:
CODE:
a=[1,2]
b=a
print("Before append: ", b)
b.append(3)
print("Shows a & b are same references, after append to b, a: ", a)
OUTPUT:
Before append: [1, 2]
Shows a & b are same references, after append to b, a: [1, 2, 3]
No comments:
Post a Comment