How to Copy a List in Python
![how to copy a list in python](https://pythonpoint.net/wp-content/uploads/2020/12/how-to-copy-a-list-in-python-1024x576.jpg)
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)
Output:
New Copied List: [1, 2, 'three']
Subscribe
Login
Please login to comment
0 Discussion