0
Need explanation why list is not getting updated since its length is getting updated.
Kindly support me to understand below code. Length of list is getting updated but element not shown when i use print command. list1=[1,2,3,4,5] list2=[1,2] ob1=list(list1) print(ob1.__len__()) print(len(list1)) ob1.append(7) print(ob1.__len__()) ob2=list(list2) ob2.append(9) print(ob2.__len__()) print(list2) print(list1)
1 Respuesta
+ 5
ob1 is not list1, and ob2 is not list2.
list() makes a new list out of the elements of the iterable you pass - it creates a copy, a clone!
So although the lengths of ob1 and ob2 may have changed, this doesn't have any influence on list1 and list2.