Back

Explore Courses Blog Tutorials Interview Questions
+3 votes
2 views
in Python by (2.6k points)
How to remove an element from a list by index in Python, I tried list.remove method but it search the list and remove it but I don't want it to perform any search. How can I do this?

2 Answers

0 votes
by (46k points)
edited by

You can use del   , it also supports slices:

>>> q = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> del a[-1]
>>> a
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Alternatively you can also use pop :

q = ['q', 'w', 'e', 'r']
q.pop()

# now q is ['q', 'w', 'e']

0 votes
by (106k points)

You probably want pop:

a = ['a', 'b', 'c', 'd']

a.pop(1)

You can use the following video tutorials to clear all your doubts:-

Related questions

+1 vote
2 answers
+3 votes
2 answers
0 votes
2 answers
asked May 30, 2019 in Python by Anvi (10.2k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...