0

Is my understanding correct? pop() remove and return the last item in the list, so it can be used to implement “First In Last Out” structure by pop(), and “First In First Out” structure by pop(0) del can also be used to delete specified index’s item. So, my question is what’s the difference between those two. If those two are the same, why would Python creator bother to create both? Is there only difference that pop() returns the remove item while del does not?

peiyuy
  • 11
  • 2

1 Answers1

1

You're correct that, for single list elements, the value or lack thereof is the only difference. However, del has a broader range of applicability: it can remove slices from a list, and it can also destroy variables, attributes, and mapping entries.

Davis Herring
  • 36,443
  • 4
  • 48
  • 76