Difference between del and remove?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Dec 12 23:38:06 EST 2007


On Wed, 12 Dec 2007 19:17:49 -0800, Yansky wrote:

> Got a quick n00b question. What's the difference between del and remove?

Everything. list.remove(value) removes the first item equal to value.
del list[index] removes the item at position index.

See also: help([].remove)


Help on built-in function remove:

remove(...)
    L.remove(value) -- remove first occurrence of value



>>> alist = [101, 102, 103, 104, 105]
>>> alist.remove(103)
>>> alist
[101, 102, 104, 105]
>>> del alist[0]
>>> alist
[102, 104, 105]


-- 
Steven.



More information about the Python-list mailing list