This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x=[1,2,3,4] | |
y=x | |
print (x)#Output:[1, 2, 3, 4] | |
print (y)#Output:[1, 2, 3, 4] | |
#Both x and y will point to same object in memory. | |
print (id(x))#Output:14563336 | |
print (id(y))#Output:14563336 | |
#'id' of int objects in list | |
print (id(x[0]))#Output:1359407024 | |
print (id(x[1]))#Output:1359407040 | |
print (id(x[2]))#Output:1359407056 | |
print (id(x[3]))#Output:1359407072 | |
# we are modifying only 'x' value.'y' value also modified. | |
x.append(5) | |
print (x)#Output:[1, 2, 3, 4, 5] | |
print(y)#Output:[1, 2, 3, 4, 5] | |
#Both 'x' and 'y' now point to same list object in memory. | |
print (id(x))#Output:14563336 | |
print (id(y))#Output:14563336 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment