Metoda .remove()
Metoda usuwa pierwszy element z listy, którego wartość jest równa wartości argumentu. Jeśli nie ma takiego elementu, zgłaszany jest błąd ValueError.
Składnia:
list.remove(item)
list.remove(item)
list.remove(item)
Parametry:
item – elementm który ma być usunięty z listy
Wartość zwracana:
None
Przykłady:
list1 = ['one', 'two', 'three', 'four', 'three']
list1.remove('three')
print(list1) # wynik --> ['one', 'two', 'four', 'three']
list1 = ['one', 'two', 'three', 'four', 'three']
list1.remove('ten')
print(list1) # wynik --> ValueError: list.remove(x): x not in list
list1 = ['one', 'two', 'three', 'four', 'three']
list1.remove('three')
print(list1) # wynik --> ['one', 'two', 'four', 'three']
list1 = ['one', 'two', 'three', 'four', 'three']
list1.remove('ten')
print(list1) # wynik --> ValueError: list.remove(x): x not in list
list1 = ['one', 'two', 'three', 'four', 'three'] list1.remove('three') print(list1) # wynik --> ['one', 'two', 'four', 'three'] list1 = ['one', 'two', 'three', 'four', 'three'] list1.remove('ten') print(list1) # wynik --> ValueError: list.remove(x): x not in list