Overview Remove ( )
Today we wil see in our website Kodlogs how we have to use the remove function in python and how to remove the value in the list .Actually four functions work the same .The function is one,Remove(),Pop(),Delete(),Clear()..Programming in python is a very easy language for people who understand English .The Remove() method takes a single element as an argument and removes it from the List.If the element
doesn't exist, It throws ValueError: list.remove(X): X not in List exception.Let’s do some practicals and learn to use these functions.
Example 1
# programmer list
programer = ['kodogs', 'Tania', 'Tabia'']
programer.remove('Tabia')
# Updated programer List
print('Updated programer list: ', programer)
OUTPUT
Update programer list:['kodlogs','Tania']
Example 2
mylist=["Tania",100,200,300,"Kodlogs",11,22,33]
mylist.remove(100)
mylist
OUTPUT
['Tania',200,300,"Kodogs',11,22,33]
Del(),Remove(),and Pop() on lists
>>> a=[7,8,9]
>>> a.remove(8)
>>> a
[7,9]
>>> a=[7,8,9]
>>> del a[1]
>>> a
[7, 9]
>>> a= [7,8,9]
>>> a.pop(1)
8
>>> a
[7,9]
>>>
Clear()
You can remove all item.
l = list(range(11))
print(l)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10]
l.clear()
print(l)
# []