11-Python Lists
11-Python Lists
Remove "banana":
thislist = ["apple", "banana", "cherry"]
thislist.remove("banana")
print(thislist)
If there are more than one item with the specified value, the remove() method removes the first
occurance:
Example
Example
If you do not specify the index, the pop() method removes the last item.
Example
Example
Example
Example
To add an item to the end of the list, use the append() method:
Example
Insert Items
Extend List
To append elements from another list to the current list, use the extend() method.
Example
The extend() method does not have to append lists, you can add any iterable object (tuples, sets,
dictionaries etc.).
Example
Example