1# removes item with given name in list
2list = [15, 79, 709, "Back to your IDE"]
3list.remove("Back to your IDE")
4
5# removes last item in list
6list.pop()
7
8# pop() also works with an index..
9list.pop(0)
10
11# ...and returns also the "popped" item
12item = list.pop()
1# Basic syntax:
2my_list.remove(element)
3
4# Note, .remove(element) removes the first matching element it finds in
5# the list.
6
7# Example usage:
8animals = ['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']
9animals.remove('rabbit')
10print(animals)
11--> ['cat', 'dog', 'guinea pig', 'rabbit'] # Note only 1st instance of
12# rabbit was removed from the list.
13
14# Note, if you want to remove all instances of an element, convert the
15# list to a set and back to a list, and then run .remove(element) E.g.:
16animals = list(set['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']))
17animals.remove('rabbit')
18print(animals)
19--> ['cat', 'dog', 'guinea pig']
1names = ['Boris', 'Steve', 'Phil', 'Archie']
2names.pop(0) #removes Boris
3names.remove('Steve') #removes Steve
1# animals list
2animals = ['cat', 'dog', 'rabbit', 'guinea pig']
3
4# 'rabbit' is removed
5animals.remove('rabbit')
6
7# Updated animals List
8print('Updated animals list: ', animals)