Python – Keywords and Identifiers
In this article, we discuss the syntax and usage details of keywords and identifiers in Python.
In Python, keywords are reserved words. It means that we cannot create custom variables or functions or any other identifier with name matching to these keywords. The python programming language defines these keywords for particular purposes.
These are some of the existing python keywords,
Essential points about Keywords in Python,
- Except for None, True and False, all keywords are in lower case.
- Keywords are case sensitive.
- You can not create identifiers with a name similar to any existing keyword.
- There are 33 keywords in python 3.7
Identifiers are the names that we choose for custom variables, functions, or classes in a python program. There are specific rules which we need to follow while selecting a name for an identifier in Python,
Rules for choosing Identifier name in Python
- The identifier can not start with a number.
- Like 2sample is an invalid identifier.
- Identifiers can contain letters (a to z or A to Z), numbers (0 to 9), and underscore (_).
- For example, value_count, dataLoader etc. are some valid identifier names.
- Python keywords cannot be used as identifiers.
- Special symbols like !, @, #, $, %, etc. are not allowed as the identifier name in Python.
- There is no limitation on the length of the identifier in Python.
- Identifiers are case sensitive, i.e., ‘sample’ & ‘Sample’ are two different identifiers in Python.
We should not use identifier names that start and ends with two underscores like __len__ or _load__ etc. Python uses these kinds of terms to define special variables and methods inside the framework classes. We should avoid using this format to create new identifiers.