Python Copy List is one of the List method, which is used to shallow copy a Lists. I mean, copying list into new list. In this article, we will show you, How to use this Python List copy function with practical examples.
Copy List Function Example
The Copy function will copy total items in a given list to a new list. Below code will copy list a to newList
TIP: Please refer List article to understand everything about Python Lists.
# Python Copy List Function a = [10, 20, 30, 40] print("Original List : ", a) newList = a.copy() print("Copied List : ", newList)
OUTPUT
In this example, we declared string list. Next, we used Copy function on it.
# Python Copy List Function strFruits = ['Apple', 'Banana', 'Kiwi', 'Grape'] print("Original List : ", strFruits) newList = strFruits.copy() print("Copied List : ", newList)
OUTPUT
Copy List Function Example 2
Let me use this Python list copy function on Mixed List.
# Python Copy List Function MixList = ['apple', 1, 'Banana', 5, 'Kiwi', 'Mango'] print("Original List : ", MixList) newList = MixList.copy() print("Copied List : ", newList)
OUTPUT
List Copy Function Example 3
In this program, we used List Copy function on Nested list (list inside list).
# Python Copy List Function MixList = [[71, 222], [222, 13], [14, 15], [99, 77]] print("Original List : ", MixList) newList = MixList.copy() print("Copied List : ", newList)
OUTPUT