Remove a few things - curiosity on del/remove


backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']

del backpack['dagger']

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


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:


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


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