Learning Python - Article 3 - What are Keywords & Identifiers?
Keywords are the reserved words in Python.
We cannot use a keyword as a variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language.
In Python, keywords are case sensitive.
There are 33 keywords in Python 3.7. This number can vary slightly as newer developments are made.
All the keywords except True, False and None are in lowercase and they must be written as it is. The list of all the keywords is given below.
| False | class | finally | is | return | break |
| None | continue | for | lambda | try | except |
| True | def | from | nonlocal | while | in |
| and | del | global | not | with | |
| as | elif | if | or | yield | |
| assert | else | import | pass | raise |
Python Identifiers
An identifier is a name given to entities like classes, functions, variables, etc. It helps us as well as the program differentiate one entity from another.
Guidelines for identifier names:
- Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore
_. Names likemyClass,var_1andprint_this_to_screen, all are valid example. - An identifier cannot start with a digit. 2nd
variableis invalid, butvariable2is acceptable. - Keywords cannot be used as identifiers. Below, using global as an identifier will provoke an error.
>>> global = 1File "<interactive input>", line 1 global = 1 ^ SyntaxError: invalid syntax - Use of special characters like !, @, #, $, % etc. in the identifier name is not permissible.
>>> a@ = 0 File "<interactive input>", line 1 a@ = 0 ^ SyntaxError: invalid syntax - Identifier can be of any length.
Points to Remember
Python is a case-sensitive language. This means, Variable and variable are not the same. Always name identifiers that make sense.
While, c = 10 is valid. Writing count = 10 would make more sense and it would be easier to figure out what it does even when you look at your code after a long gap.
Multiple words can be separated using an underscore, this_is_a_long_variable.


