Python List – copy()
Python list.copy() method makes a shallow copy of the elements in original list, and returns the copy.
Syntax
The syntax to call copy() method on a list myList is
</>
                        Copy
                        myList.copy()where
- myListis a Python list
- copyis method name
Examples
Copy a List
In the following program, we initialize a list myList with some elements. We copy this list into a new list copyList, using copy() method.
main.py
</>
                        Copy
                        #take a list
myList = ['apple', 'banana', 'cherry']
print(f'original list : {myList}')
#make a copy of the list
copyList = myList.copy()
print(f'list copy     : {copyList}')Output
original list : ['apple', 'banana', 'cherry']
list copy     : ['apple', 'banana', 'cherry']Conclusion
In this Python Tutorial, we learned how to copy elements of a list into another list, using list.copy() method.
