In this article, you learn about Python identifiers. In Python, identifiers are the names given to identify variables, functions, classes, modules, etc.
Identifiers are like the names that your parents gave you for your identification. Similarly, in Python programming, a programmer can write identifiers to identify different objects.
Example 1: Python identifiers
Age = 27
A= 5
FirstName = “john”
In the above example “age”, “a” and “FirstName” are identifiers.
Rules to writing a valid Python identifier
In Python, there are some rules to write valid identifiers that are given below.
- The identifier can be letters, digits, and underscore (Aa-Zz, 0-9, and _)
- An identifier cannot begin with digits but can start with an underscore and letters
- Keywords cannot be used as identifiers
- They are case sensitive which means “A” and “a” are two different identifiers
- We cannot use special symbols as an identifiers
Example 2: Some valid Python identifiers
Students
Subject2
User_Name
logic
_age
Example 3: Some invalid Python identifiers
Student Marks
2num
Your-name
!number