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 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.

# Python Copy List Function

a = [10, 20, 30, 40]

print("Original List : ", a)
newList = a.copy()
print("Copied List   : ", newList)

List copy function output

Original List :  [10, 20, 30, 40]
Copied List   :  [10, 20, 30, 40]

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

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

# Python Copy List Function

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

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

copy List Function Example 2

Let me use this 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)

List copy function output

Original List :  ['apple', 1, 'Banana', 5, 'Kiwi', 'Mango']
Copied List   :  ['apple', 1, 'Banana', 5, 'Kiwi', 'Mango']

List copy Function Example 3

In this program, we used List copy function on the Nested list (list inside a 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)

List copy function output

Original List :  [[71, 222], [222, 13], [14, 15], [99, 77]]
Copied List   :  [[71, 222], [222, 13], [14, 15], [99, 77]]