What is the difference between the following lines of codes

code1: list1=[1,3,5,6]  


code2: list1=[1,3,5,6]



Code 1

Code 2

In code 1, No new list is created instead a reference is made to the old list ie., list2 just references list1. 

In code 2, A new copy of list1 is created and assigned to list 2.

Whenever any change is made to any of the lists, it reflects in the other.

Any change made to either of the lists is not reflected in the other.



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.