In this post, we will look at different ways of removing elements from the list.

Python Remove From List

Example: Remove or delete element 'Engineer' from following list using list.remove(value) method.

mylist = ['James', 'John', 'Engineer', 'Singer']
mylist.remove('Engineer')
mylist

Output of above command...

['James', 'John', 'Singer']

Python Remove Last Element From List

Example: Remove or delete last element from following list list.pop() method...

mylist = ['James', 'John', 'Engineer', 'Singer']
mylist.pop()
mylist

Output of above command...

['James', 'John', 'Engineer']

Of course if you know the value of last element in the list, you can use list.remove(value) method to remove element by value.

Python Remove Item From List By Index

Example: Remove or delete 2nd element from following list...

mylist = ['James', 'John', 'Engineer', 'Singer']

2nd element will be John, since in Python index starts from 0. To remove by index command is...

del mylist[1]
mylist

Output of above command list...

['James', 'Engineer', 'Singer']

Python Remove List

Last but not least, one can remove the list altogether.

Example: Remove or delete following list...

mylist = ['James', 'John', 'Engineer', 'Singer']
del mylist

Now let us print the mylist...

print(mylist)

You should see following output...

NameError: name 'mylist' is not defined

Note: del mylist can delete not only list but any object.

Check out how to use append in Python also.