1. Help Center
  2. Python Programming

What Is the Difference Between Del and Remove() on Lists?

del removes all elements of a list within a given range
Syntax: del list[start:end]
remove() removes the first occurrence of a particular character
Syntax: list.remove(element)
Here is an example to understand the two statements -
 
>>lis=[‘a’, ‘b’, ‘c’, ‘d’]

 

>>del lis[1:3]

 

>>lis

 

Output: [“a”,”d”]

 

>>lis=[‘a’, ‘b’, ‘b’, ‘d’]

 

>>lis.remove(‘b’)

 

>>lis

 

Output: [‘a’, ‘b’, ‘d’]

 

 
Note that in the range 1:3, the elements are counted up to 2 and not 3.