Keywords are the reserved words in the Python language that define the syntax of the coding. Identifiers are the names given to variables, functions, classes, modules, etc. We can not use the keywords as a function, identifier, and variable name.
Python Keywords
Keywords are case sensitive in Python. All Keywords (except True and False) are written in lower case.
There are 35 keywords in Python 3.7.3 version. The list of all the keywords is given below.
False |
await |
else |
import |
pass |
None |
break |
except |
in |
raise |
True |
class |
finally |
is |
return |
and |
continue |
for |
lambda |
try |
as |
def |
from |
nonlocal |
while |
assert |
del |
global |
not |
with |
async |
elif |
if |
or |
yield |
Python Identifiers
The identifier is a combination of underscore, characters, and digits.
Rules for writing identifiers
1. Identifiers can be a combination of underscore ‘_’ or letters (a to z) or (A to Z) or digits (0 to 9). For example: _var2, var_2, _2_var etc.
2. An identifier always starts with an underscore or alphabet. It cannot start with a digit.
3. Any Python Keywords cannot be used as identifiers.
continue = 1
Output
File "", line 1 continue = 1 ^ SyntaxError: invalid syntax
4. We cannot use special characters like $, %, !, @, #, etc. in our identifier.
b@ = 0
Output
File "", line 1 a@ = 0 ^ SyntaxError: invalid syntax
5. Wen can use an identifier of any length.