Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Is there any difference between "del a" and "del(a)"?

Tags:

python

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?

like image 352
RuqX Avatar asked Aug 17 '15 21:08

RuqX


People also ask

What is the difference between del () and remove () methods of list?

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.

Why is Del not a function Python?

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!

Is Del a function in Python?

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.

When should I use del in Python?

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.


Video Answer


1 Answers

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.

like image 58
cdonts Avatar answered Oct 05 '22 23:10

cdonts