Python Identifiers
Table Of Contents
- What Are Python Identifiers?
- Rules For Writing Identifiers.
- Valid Identifiers Example.
- Invalid Identifiers Example.
What Are Python Identifiers ?
- We need a name and address to identify someone present in this world.
- Likewise in python, we need a name to identify a class, functions, and variables present inside computer memory.
- By giving a name to an entity, it will be easier for us to call and use them when needed.
Rules For Writing Python Identifier
- The identifier is a combination of character digits and underscore and the character includes letters in lowercase (a-z), letters in uppercase (A-Z), digits (0-9), and an underscore (_).
- An identifier cannot begin with a digit. If an identifier starts with a digit, it will give a Syntax error.
- In Python, keywords are the reserved names that are built-in to Python, so a keyword cannot be used as an identifier – they have a special meaning and we cannot use them as identifier names.
- Special symbols like !, @, #, $, %, etc. are not allowed in identifiers.
- Python identifiers cannot only contain digits.
- There is no restriction on the length of identifiers.
- Identifier names are case-sensitive.
Valid Identifier Examples
- abc123
- abc_de
- _abc
- ABC
- abc
- var1
- _var1
- _1_var
- var_1
- __varvar
Invalid Identifier Examples
- 123abc
- abc@
- 123
- for
- !var1
- 1var
- 1_var
- var#1