python 3.x - Assignments in integers and lists -
a=2 b=3 a=b a=a+12 print(a) print(b)
output :
15 3
when did kind of thing in lists:
list1=[1,2,3,4] list2=[4,5,6,7] list1=list2 list1.append(12523) print(list1) print(list2)
output:
[4, 5, 6, 7, 12523] [4, 5, 6, 7, 12523]
whenever changed value of , b doesn't change @ all.but in second when changed list1 , list2 changes automatically.can ask why happens ?
it's because of data type used, first have a = b
(both integers, primitive types) , such happen in a = b
a = 3
. in second case have list (not primitive type) ,list1 = list2
list1 point same place in memory list2 pointing to, change make change place in memory both list1 , list2 pointing towards
Comments
Post a Comment