The copy method
The copy method makes a copy of the list. We do not specify anything in the method parameter.
Syntax
list.copy()
Example
Let's copy our list using the copy method:
lst1 = ['ab', 'cd', 'ef']
lst2 = lst1.copy()
print(lst2)
Result of code execution:
['ab', 'cd', 'ef']
Example
However, by using the copy method we only create a so-called shallow copy of the list - changes we make to the original list after copying will not affect the copy:
lst1 = ['ab', 'cd', 'ef']
lst2 = lst1.copy()
lst1.append('jh')
print(lst1)
print(lst2)
Result of code execution:
['ab', 'cd', 'ef', 'jh']
['ab', 'cd', 'ef']