Menu Close

How to delete a list element by value with Python?

Sometimes, we want to delete a list element by value with Python.

In this article, we’ll look at how to delete a list element by value with Python.

How to delete a list element by value with Python?

To delete a list element by value with Python, we can use the remove method.

For instance, we write

xs = ["a", "b", "c", "d"]
xs.remove("b")

to call xs.remove with ‘b' to remove 'b' from the xs list.

Conclusion

To delete a list element by value with Python, we can use the remove method.

Posted in Python, Python Answers