Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

Python Copy List Function

by suresh

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

Python Copy List Function 1

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

Python Copy List Function 2

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

Python Copy List Function 3

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

Python Copy List Function 4

Placed Under: Python

Trending Posts

How to Join Data in Tableau

MySQL Week Function

Java Else If Statement

SQL DAY Function

MDX ParallelPeriod Function

Add Video to Power BI Dashboard

Python isnumeric

Python RIndex

Install SQL Server Management Studio

Report History Snapshot in SSRS

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy