Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 25, 2020 02:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save IndhumathyChelliah/403ebba2033589771e5b01077941d470 to your computer and use it in GitHub Desktop.
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