home ~ projects ~ socials

Remove An Item From A Python List With .remove()

TL;DR

Use .remove() to remove a value from a Python list.

people = ['Jen', 'Greg', 'Jonas']

if 'Greg' in people:
    people.remove('Greg')

print(people)
Output:
['Jen', 'Jonas']

If you don't check to see if the value is in the list and try to remove one that isn't there it'll throw an error.

-- end of line --