0 votes
in Python by
What is the difference between remove() function and del statement?

1 Answer

0 votes
by

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

Example:

  1. list_1 = [ 357393 ]   
  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 = [ 357393 ]   
  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]

Related questions

0 votes
asked Feb 4, 2020 in Cloud Computing by SakshiSharma
0 votes
asked May 12, 2019 in Other by anonymous
0 votes
asked Sep 12, 2022 in Scala Constructs by Robin
...