+ 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😊

31st Aug 2020, 7:00 AM
Sahan Illangasinghe
Sahan Illangasinghe - avatar
3 odpowiedzi
+ 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
31st Aug 2020, 7:14 AM
HonFu
HonFu - avatar
+ 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.
31st Aug 2020, 7:11 AM
Web-Learner
+ 1
I see....... thnx alot everybody😀😀✌👍👍
31st Aug 2020, 7:35 AM
Sahan Illangasinghe
Sahan Illangasinghe - avatar