0

List assignment in python

num1=[1,2,3,4] num2=num1 print(num1) num2[0]=5 print(num1[0]) Above code last line output 5, why?

25th Apr 2017, 10:21 AM
Prakhar Jain
Prakhar Jain - avatar
1 Resposta
+ 9
Array is by default reference type. If you assign a array to another variable. That variable has the same reference to that array. if you change value of one array others will also change.
25th Apr 2017, 10:32 AM
Cyrus Ornob Corraya
Cyrus Ornob Corraya - avatar