Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

delete item from list python

list_ = ["lots", "of", "items", "in", "a", "list"]

# Remove an item by index and get its value: pop()
>>> list_.pop(0)
'lots'
>>> list_
["of", "items", "in", "a", "list"]

# Remove an item by value: remove()
>>> list_.remove("in")
>>> list_
["of", "items", "a", "list"]

# Remove items by index or slice: del
>>> del list_[1]
>>> list_
['of', 'a', 'list']

# Remove all items: clear()
>>> list_.clear()
>>> list_
[]
Source by alexandra-zaharia.github.io #
 
PREVIOUS NEXT
Tagged: #delete #item #list #python
ADD COMMENT
Topic
Name
6+5 =