Here, we will figure out how to expel all components in a range from the list in Python? To evacuate all components in a range from the list we use del() strategy for python.
Given a list and we need to expel components in a range from the list in Python.
del list(start_index, end_index):
del() technique is utilized to expel all components of the list in extend beginning 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