QUES 7 of ML Assignment 0 - Python Fundamentals

can’t understand the different nature of the output

can u please specify which exact code linr or variable which u can’t understand

sir in list 2 when we are passing (123,[])
are we making a new list there
if so then why list 1 and list3 not seperate list kyuki har bar extendlist[] function mei to (val,list[]) pass ho rhi h

Lists need not be homogeneous always which makes it a most powerful tool in Python. A single list may contain DataTypes like Integers, Strings, as well as Objects.
also list in python are muttable
so
-> when we pass L2 =[1,2,3] it makes a list [1,2,3] in memory then point back it to L2
->when we did L3.extend(L2) then it will do L3 = L3+L2

  • so yes we are creating new list in l2 = list([1,2,3])

  • and in l3 = list(l2) we also generate new list for l3
    if we have done l3 = l2 then we would not have created new list and refead same address

l2 = [1,5,8]
l3 = list(l2)
l3.extend(l2)
l2 = [1,5,8]
l3 = [1,5,8,1,5,8]
/////////////
and when we did
l2 = [1,5,8]
l3 = (l2)
l3.extend(l2)
we get
l2 =[1,5,8,1,5,8]
l3 =[1,5,8,1,5,8]