# importing "copy" for copy operations import copy # initializing list 1 list1=[1,2,[3,5],4] # using deepcopy to deepcopy list2=copy.deepcopy(list1) id(list1), id(list2)
The deepcopy() function makes a copy of the list but unlike the copy(), the deepcopy() function also copies the values of the list and the objects they reference. It creates a new list and recursively adds copies into it of the objects found in the original list. The id() function returns a unique id for the object.