Answer is no. You can e.g. use function as an identifier.
>>> function = 5
>>> function
5
E.g. def or if are keywords and you can not do so.
>>> if = 5
File "<stdin>", line 1
if = 5
^
SyntaxError: invalid syntax
>>> def = 6
File "<stdin>", line 1
def = 6
^
SyntaxError: invalid syntax
It is also not a built-in identifier as is e.g. print or map:
$ python
Python 3.10.6 (main, May 29 2023, 11:10:38) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> function
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'function' is not defined
3
Answers
Python offers a
keyword
module that can list both hard and soft keywords present in a language –function
is not among them.function
is not a reserved word, please see below according to the python documentation, please refer below.https://docs.python.org/3/library/keyword.html?highlight=keywords
https://github.com/python/cpython/blob/3.11/Lib/keyword.py
This module allows a Python program to determine if a string is a keyword or soft keyword.
keyword.iskeyword(s)
Return True if s is a Python keyword.
Here is the list of keywords:
https://docs.python.org/3/reference/lexical_analysis.html?highlight=keywords#keywords
Answer is no. You can e.g. use
function
as an identifier.E.g.
def
orif
are keywords and you can not do so.It is also not a built-in identifier as is e.g.
print
ormap
: