+ 1
Que. about python 'lists' and 'del' !!!
#code L1 =["A","B","C"] L2 = L1 L3 = L2 del L1[0] del L2 print(L3) ....... #output: ['B','C'] #question 1 In here when I used "del L2", Why does it still output B and C ??? #question 2 But when change "del L2" to "del L2[:]" , output will be [ ] . It outputs nothing!!! I'm confusedđ, some help will be appreciatedđ
3 Answers
+ 7
All your lists are actually just one list with three names.
del l2 only deletes one of the names. The list exists on, with two names.
del l2[:] removes the content of the list. And since in reality you have only one list, it happens in 'all of them'.
Detailed explanation:
https://code.sololearn.com/c89ejW97QsTN/?ref=app
+ 2
#answer1
del L2 only deletes the variable.
Not values.
So , The Output comes the same as the above.
#answer2
del L2[:]
L2[:]=The whole list.
Since You deletes the entire list,
It shows nothing.
+ 1
I see....... thnx alot everybodyđđâđđ