How to Remove Elements from a List in Python: A Step-by-Step Guide

Rumman Ansari   Software Engineer   2024-07-26 07:00:14   266  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Python provides the remove() function which is used to remove the element from the list. Consider the following example to understand this concept.

Example


list = [0,1,2,3,4]     
print("printing original list: ");    
for i in list:    
    print(i,end=" ")    
list.remove(2)    
print("\nprinting the list after the removal of first element...")    
for i in list:    
    print(i,end=" ")  

Output


printing original list: 
0 1 2 3 4 
printing the list after the removal of first element...
0 1 3 4