Home » Python programs

Python | Program to remove all elements in a range from the List

Here, we are going to learn how to remove all elements in a range from the list in Python? To remove all elements in a range from the list we use del() method of python.
Submitted by IncludeHelp, on July 21, 2018

Given a list and we have to remove elements in a range from the list in Python.

del list(start_index, end_index)

del() method is used to remove all elements of list in range starting from start_index to end_index.

Syntax:

 del list(start_index, end_index)

Program:

# Declaring a list
list = [10, 20, 30, 40, 50]

# print list
print "List element:"
for l in range(len(list)):
	print (list[l])

# delete element from index 1 to 30del list[1.3]
del list[1:3]

# print list after deleting
# element from index 1 to 3
print "List element after del[1:3]:"
for l in range(len(list)):
	print (list[l])

Output

    List element:
    10
    20
    30
    40
    50
    List element after del[1:3]:
    10
    40
    50





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.