Why is the del
builtin function not mentioned in the builtin functions docs ? is it a bug?
I was doing a python tutorial which mentioned del
and wanted to read the official docs about it, but I can’t find it.
Regards,
Why is the del
builtin function not mentioned in the builtin functions docs ? is it a bug?
I was doing a python tutorial which mentioned del
and wanted to read the official docs about it, but I can’t find it.
Regards,
del
is not a function, it’s a syntax construct: 7. Simple statements — Python 3.12.6 documentation
Thank you.
I’m Python newbie so didn’t know if it was a builtin function or statement, I just googled “python del builtin” and was referenced to the aforementioned page.
Thanks for clarifying.
You tell by looking for parens, the function-calling syntax. del
doesn’t use them so it’s not a function.
Note that in case of doubt you can ask the Python interpreter: you can type a function name and you will get the function object.
>>> abs
<built-in function abs>
But you can’t type del
keyword alone, it’s a syntax error.
>>> del
File "<stdin>", line 1
del
^
SyntaxError: invalid syntax
Also you can ask for help about the keyword:
>>> help('del')
The "del" statement
*******************
del_stmt ::= "del" target_list
Deletion is recursively defined very similar to the way assignment is
defined. Rather than spelling it out in full details, here are some
hints.
Deletion of a target list recursively deletes each target, from left
to right.
Deletion of a name removes the binding of that name from the local or
global namespace, depending on whether the name occurs in a "global"
statement in the same code block. If the name is unbound, a
"NameError" exception will be raised.
Deletion of attribute references, subscriptions and slicings is passed
to the primary object involved; deletion of a slicing is in general
equivalent to assignment of an empty slice of the right type (but even
this is determined by the sliced object).
Changed in version 3.2: Previously it was illegal to delete a name
from the local namespace if it occurs as a free variable in a nested
block.
Related help topics: BASICMETHODS