Can keywords be used as identifiers in Python? Please explain about keywords and identifiers can we use it in all workstation?
Yes or No If yes then how? If No then how?
Can keywords be used as identifiers in Python? Please explain about keywords and identifiers can we use it in all workstation?
Yes or No If yes then how? If No then how?
Pretty easy to find the answer to this question:
>>> class = 56
File "<stdin>", line 1
class = 56
^
SyntaxError: invalid syntax
>>> def = 42
File "<stdin>", line 1
def = 42
^
SyntaxError: invalid syntax
No, you cannot use keywords as variable names.
However, you can use the names of built-in types as variable names. It shows up on SO all the time, and it's a very bad idea because that built-in type then becomes unavailable.
E.g.
>>> from collections import defaultdict
>>> list = [42, 27]
>>> d = defaultdict(list)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: first argument must be callable or None