A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).
Here are naming conventions for Python identifiers −
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
- Starting an identifier with a single leading underscore indicates that the identifier is private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
Keywords cannot be used as identifiers. Example:
global = 1
Output
File "<interactive input>", line 1 global = 1 ^ SyntaxError: invalid syntax
We cannot use special symbols like !, @, #, $, % etc. in our identifier. Example:
a@ = 0
Output
File "<interactive input>", line 1 a@ = 0 ^ SyntaxError: invalid syntax