Why is remove used when we have del?


Why is remove used when we have del?


There are three methods for removing items from lists in Python, and which one you use depends on your purpose:

Removes the first matching value rather than an index

del foo[index]
Removes a specific index

Removes a specific index and returns the removed element


The course doesn't tell us about pop. :stuck_out_tongue: anyway thx


ambiguous this foo.pop command (index) Removes a specific index and returns the element removed as I remove and use, to that remove will use the same way found useless


I'm afraid I don't quite follow you. What do you find ambiguous?

This simply means that the return value of the foo.pop() operation is the removed element.


but has command that returns the value without need to remove it


There are indeed, but these are all operations intended to remove the element.

There may well be a situation where you want to both remove the element and use it - for example, deleting an element from a list and displaying it to the user (so they can confirm which element was removed). This is simply a shortcut for doing so.


do sense for python is what is server and interact with client what is the user


I need help with the remove function
Remove 'dagger' from the list of items stored in the backpack variable.
backpack = ['xylophone', 'dagger', 'tent', 'bread loaf']
Oops, try again.
backpack has to be a list! Click Reset Code to get back to the original code.

What am I doing wrong?


The code finally worked upon refreshing the page..Thanks ladies and gents