Q:

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

belongs to collection: Python List Programs

0

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)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python List Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Python | Program to sort the elements of given lis... >>
<< Python | Remove all occurrences a given element fr...