ITP

BSc IT - Programming in Python

Difference between remove() function and del statement

In : BSc IT Subject : Programming in Python

`remove()` deletes the first occurrence of a specific value from a list and raises an error if the value is not found.

The `del` statement removes an item at a specific index or deletes the entire list. Use `remove()` when you know the value, and `del` when you know the index.

Example :

fruits = ["apple", "banana", "cherry"]
fruits.remove("banana")
print(fruits)  # Output: ['apple', 'cherry']

fruits = ["apple", "banana", "cherry"]
del fruits[1]
print(fruits)  # Output: ['apple', 'cherry']

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap