Remove a few things - curiosity on del/remove


#1


backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']
backpack.remove('dagger')

del backpack['dagger']

What is the difference between these line? Why the second one doesn't work?


#2

Hi @pywhiz20396,

simply because it should be del backpack[1] instead of del backpack['dagger']; del uses index instead of the item name :stuck_out_tongue:


#3

Oh, ok. I didn't had clearly understood the index meaning. Thanks :slight_smile:


#4

welcome :slight_smile: remember to mark the question as solved, thank you :slight_smile: