Python copy List Function

Python copy List is one of the List methods used to shallow copy a Lists. I mean, copying list into a new list. The syntax of the Python list copy function is

list_name.copy()

Python List copy Function Example

The copy function copies total items in a given list to a new list. The below code copy list a to newList.

a = [10, 20, 30, 40]

print("Original List : ", a)
newList = a.copy()
print("Copied List   : ", newList)
Original List :  [10, 20, 30, 40]
Copied List   :  [10, 20, 30, 40]

In this Python list copy example, we declared a string list. Next, we used the copy function on it.

strFruits = ['Apple', 'Banana', 'Kiwi', 'Grape']

print("Original List : ", strFruits)
newList = strFruits.copy()
print("Copied List   : ", newList)
Python Copy List Function 2

TIP: Please refer to List and List methods articles in Python.

This List copy method example shallow copies the list items into a completely new list.

# List copy

Fruits = ['Apple', 'Orange', 'Banana', 'Kiwi', 'Grape', 'Blackberry']
numbers = [9, 4, -5, 0, 22, -1, 2, 14]

print("Original List : ", Fruits)
print("Original number List : ", numbers)

#Copying the List
New_Fruits = Fruits.copy()
print("\nNew List : ", New_Fruits)

new_numbers = numbers.copy()
print("New Number List : ", new_numbers)
Original List :  ['Apple', 'Orange', 'Banana', 'Kiwi', 'Grape', 'Blackberry']
Original number List :  [9, 4, -5, 0, 22, -1, 2, 14]

New List :  ['Apple', 'Orange', 'Banana', 'Kiwi', 'Grape', 'Blackberry']
New Number List :  [9, 4, -5, 0, 22, -1, 2, 14]

copy List Function Example 2

Let me use this list copy function on Mixed List.

MixList = ['apple',  1, 'Banana', 5, 'Kiwi', 'Mango']

print("Original List : ", MixList)
newList = MixList.copy()
print("Copied List   : ", newList)
Original List :  ['apple', 1, 'Banana', 5, 'Kiwi', 'Mango']
Copied List   :  ['apple', 1, 'Banana', 5, 'Kiwi', 'Mango']

In this program, we used List copy function on the Nested list (list inside a list).

MixList = [[71, 222], [222, 13], [14, 15], [99, 77]]

print("Original List : ", MixList)
newList = MixList.copy()
print("Copied List   : ", newList)
Original List :  [[71, 222], [222, 13], [14, 15], [99, 77]]
Copied List   :  [[71, 222], [222, 13], [14, 15], [99, 77]]