Copy an Object in Python using = operator

26

list1 = [['a', 8, 7], [6, 5, 4], [3, 2, 1]]
list2 = list1
list2[0][0] = 9
print('Old List:', list1)
print('ID of Old List:', id(list1))
print('New List:', list2)
print('ID of New List:', id(list2))

Comments

Submit
0 Comments