.remove(item) vs. del dict_name[key_name]


what is the diffrence between
.remove(item) and del dict_name[key_name] ????


There are three methods for removing items from lists in Python:

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 .remove(item) will remove the first matching item from your list.The ideas is not specified here.

numbers = [1,1,2,2,3,3,4,4]
print(numbers)#[1, 1, 2, 2, 3, 4, 4]

The del method will remove an item at the specified index of your data structure

numbers = [1,1,2,2,3,3,4,4]
del numbers[1]# delete whatever is at index 1
print(numbers)#[1, 2, 2, 3, 3, 4, 4]

13. remove a Few Things



thanx to all of you. this helped a ton!