remove() to remove item based on value from a list
« All list methods
remove(x) takes one argument as matching value .
x
: ( value ) first matching value to be removed
my_list=['Alex','Ronald','John']
my_list.remove('Ronald')
print(my_list)
Output is here
['Alex', 'John']
Having duplicate values
Only first matching value is removed.
my_list=['Alex','Ronald','John','Ronald','Ronn']
my_list.remove('Ronald')
print(my_list)
Output ( 2nd matching element Ronald is not removed. )
['Alex', 'John', 'Ronald', 'Ronn']
« All list methods « Questions with solutions on List
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com