- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between del, remove and pop on lists in python ?
It does't matter how many lines of code you write in a program. When you want to remove or delete any elements from the Python list, you have to think about the difference between remove, del and pop in Python List and which one to use
remove : remove() removes the first matching value or object, not a specific indexing. lets say list.remove(value)
Example
list=[10,20,30,40] list.remove(30) print(list)
Output
[10, 20, 40]
del : del removes the item at a specific index. lets say del list[index]
Example
list = [10,20,30,40,55] del list[1] print(list)
Output
[10, 30, 40, 55]
pop : pop removes the item at a specific index and returns it. lets say list.pop(index)
Example
list = [100, 300, 400,550] list.pop(1) print(list)
Output
[100, 400, 550]
Advertisements