Write a program to demonstrate the three different ways of copying a list.

 

Answer:

Code:

import copy 

list1=[ 'red' , 'green' , 'blue' , 'yellow' , 'orange'

 

#method 1 

list2= list1 

print (list2) 

 

#method 2 

list3=copy.copy(list1) 

print(list3) 

 

#method 3 

list4=list1[:] 

print(list4)

 

Question 1 Long Answer.jpg

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 13 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.