How to Copy a List in Python
A list can be copied using = operator. But the problem with it is that, if we make any changes to the initial list, that change will appear on the new list also. This happens because, the = operator creates a referencing or pointing to the same old list.
The copy() method can be used to make a copy of the required list, not a referencing. The copy() method doesn’t take any parameters.
old_list = [1, 2, 'three'] new_list = old_list.copy() print("New Copied List: ", new_list)
New Copied List: [1, 2, 'three']
Please login to comment
View all comments