peiyuy peiyuy - 5 months ago 33
Python Question

the difference between pop() and del keyword

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download