The List.copy()
method is one of the many list methods in Python. The List.copy()
method is simply used to get the copy of a list.
List.copy()
List.copy()
does not take any parameters.
Let’s create a list of even numbers up to 10. We use List.copy()
to get a copy of the list we create.
even_numbers = [2, 4, 6, 8, 10]# now let us have a copy of our specified list in another listeven_numbers2 = even_numbers.copy()print(even_numbers2)
even_numbers
.even_numbers2
.even_numbers2
, which contains the copied items from the original list, even_numbers
.Note: Whenever you copy the items of a list to a new list, they become entirely independent. That is, any modification done to either of the two lists has nothing to do with the other.