Identifiers in Python
An Identifier is a user-defined name given to a variable, function, class, module,
etc. The identifier is a combination of character digits and an underscore. They are
case-sensitive i.e., ‘num’ and ‘Num’ and ‘NUM’ are three different identifiers in
python. It is a good programming practice to give meaningful names to identifiers to
make the code understandable.
We can also use the Python string isidentifier() method to check whether a string is
a valid identifier or not.
Rules for Naming Python Identifiers
It cannot be a reserved python keyword.
It should not contain white space.
It can be a combination of A-Z, a-z, 0-9, or underscore.
It should start with an alphabet character or an underscore ( _ ).
It should not contain any special character other than an underscore ( _ ).
Examples of Python Identifiers
Valid identifiers:
var1
_var1
_1_var
var_1
Invalid Identifiers
!var1
1var
1_var
var#1
var 1