Special welcome gift. Get 50% off your first courses with code “AS50”. Find out more!

HomeInterviewWhat is the difference between remove() function and del statement?
course 10

What is the difference between remove() function and del statement?

The user can use the remove() function to delete a specific object in the list.

Example:

  1. list_1 = [ 3, 5, 7, 3, 9, 3 ]   
  2. print(list_1)  
  3. list_1.remove(3)   
  4. print(“After removal: “, list_1)  

Output:[3, 5, 7, 3, 9, 3] After removal: [5, 7, 3, 9, 3]

If you want to delete an object at a specific location (index) in the list, you can either use del or pop.

Example:

  1. list_1 = [ 3, 5, 7, 3, 9, 3 ]   
  2. print(list_1)  
  3. del list_1[2]  
  4. print(“After deleting: “, list_1)  

Output:[3, 5, 7, 3, 9, 3] After deleting: [3, 5, 3, 9, 3]

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

Categories

ads sidebar 1

You May Also Like

Oracle has several modes for shutting down the database: In normal mode, the database is shut down by default. It...
Materialized views are items that contain condensed sets of data from base tables that have been summarized, clustered, or aggregated. They...
Every database in Oracle has a tablespace called SYSTEM, which is generated automatically when the database is created. It also...