Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

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

** TL;DR

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

Code

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

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

print(people)

Results

['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.