How to Use List copy() Method in PythonPython Basics


The copy() method is used to perform a shallow copy of the list.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

list1 = ['e', 'a', 'u', 'o', 'i']
print(list1)

list2 = list1.copy()
print(list2)

Output:

['e', 'a', 'u', 'o', 'i']
['e', 'a', 'u', 'o', 'i']

Syntax

list.copy()

Parameters

The method doesn’t take any parameters.

Return Value

It returns a list.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us