Member-only story

Python Programming Language: How to Remove Elements From a List

Jesse L
3 min readJun 28, 2022

--

Hi everyone, welcome back. In these examples, we will be going over how to remove elements from a List in Python. Lists can be used to store a collection of data. A List in Python is mutable and can allow duplicate values. The elements within a List are indexed and ordered. With this introduction out of the way, let’s get into it.

Creating List

Let’s start by creating our List with populated values:

myList = [1, 2, 3]
print(myList)
Output:
[1, 2, 3]

So now, we have a populated List with a few elements. We can verify that it was successfully created and populated by printing the List and checking the output. Now, let’s see how we can remove elements.

Removing by Value

Let’s try to remove an element from the List by its value. We can do this by using the built in remove() function that is provided. Let’s see an example:

myList = [1, 2, 3]
myList.remove(1)
print(myList)
Output:
[2, 3]

In the example above, we can see that we removed the number “1” from our List by using the remove() function. We can verify that it was successfully removed by printing our List and checking the output.

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet