a = [10, 20, 30, 20]
a.remove(20)
# a = [10, 30, 20]
# removed first instance of argument
# the list.remove(object) method takes one argument
# the object or element value you want to remove from the list
# it removes the first coccurence from the list
generic_list = [1, 2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]
generic_list.remove(1)
# The Generic list will now be:
# [2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]
l1 = [1, 8, 7, 2, 21, 15]
# l1.remove(21) # removes 21 from the list
print(l1)
Python Program to remove an element from the list
# list of cars
cars = ['Benz','BMW','Ford','Ferrari','volkswagen']
# remove Ferrari car from the list
cars.remove('Ferrari')
# Updated car list
print("Updated Car list = ",cars)
>> list = ["Facebook", "Instagram", "Snapchat", "Twitter", "TikTok"]
>> list.remove("Snapchat")
>> print(list)
["Facebook", "Instagram", "Twitter", "TikTok"]
#original list
programming_languages = ["JavaScript", "Python", "Java", "C++"]
#print original list
print(programming_languages)
# remove the value 'JavaScript' from the list
programming_languages.remove("JavaScript")
#print updated list
print(programming_languages)
#output
#['JavaScript', 'Python', 'Java', 'C++']
#['Python', 'Java', 'C++']
programming_languages = ["JavaScript", "Python", "Java", "Python", "C++", "Python"]
programming_languages.remove("Python")
print(programming_languages)
#output
#['JavaScript', 'Java', 'Python', 'C++', 'Python']