Python List copy() MethodPython copy() method copies the list and returns the copied list. It does not take any parameter and returns a list. The method signature and examples are given below. SignatureParametersNo parameter ReturnIt returns a copy of the list. Let's see some examples of copy() method to understand it's functionality. Python List copy() Method Example 1A Simple example which copy a list ot another and makes an new list. See the example below. Output: Original list: [6, 8, 2, 4] Copy list: [6, 8, 2, 4] Python List copy() Method Example 2Here, we are using list slicing concept to create a copy of the list. See the example below. Output: Original list: [6, 8, 2, 4] Copy list: [6, 8, 2, 4] Python List copy() Method Example 3The assignment operator can also be used to copy a list into another. This is most general approach but not recommended. Output: Original list: [6, 8, 2, 4] Copy list: [6, 8, 2, 4]
Next TopicPython Lists
|