As far as I can tell, both del a
and del(a)
seems to work with the same effect. If that's the case, why would Python allow del
to exist both as a statement and a function?
The remove() method doesn't return any value. pop() returns deleted value. The del keyword can delete the single value from a list or delete the whole list at a time. At a time it deletes only one value from the list.
Because del is a statement that you can delete several things with it, and since when you want to delete list_name[index] with del actually you want to delete an object and this is the job that del does for other objects so there is no need to create an redundant attribute for lists to does that!
The del keyword in python is primarily used to delete objects in Python. Since everything in python represents an object in one way or another, The del keyword can also be used to delete a list, slice a list, delete a dictionaries, remove key-value pairs from a dictionary, delete variables, etc.
The del keyword is used to delete objects. In Python everything is an object, so the del keyword can also be used to delete variables, lists, or parts of a list etc.
del
is always a statement. Using parenthesis doesn't mean you're making a function call, but you're grouping expressions. (1)
is just the same as 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With