python identifiers

Python identifiers are nothing but a name in the python program
for example to identify a thing or a person we have names same as in python it is called as identifiers.

An identifier can be a variable name or a method name or a class name.
Example:
a = 5
here 'a' which can be used to represent
where a is a name of the variable to represent the 5

Where there are some rules to define or to create identifiers they are as follows as
Rule 1:
It allows only characters (ALPHABETS) i.e., capital letters from A to Z
and small letters a to z
and digits from  0 to 9
and only one special symbol is allowed i.e.,  " _ " (underscore)
Except this if you try to enter any other symbols it will show a syntax error.
where a syntax error is the most common and basic error that occurs when the python parser is unable to understand the line of code.

Rule 2:
The identifiers should start with characters only.
and it should not start with digits 
that is we can write or start identifiers name by characters and along with that we can also use the only symbol that is (underscore _) 
Example:
NAME ="zaheer"   ✔
Name = "zaheer"    ✔
_name = "zaheer"    ✔
_NAME = "zaheer"  ✔
NAme123 = "zaheer"  ✔

But we cannot start with any symbols or digits, If we use it again it will show a syntax error.
123name = "zaheer" ❌
$name = "zaheer" ❌

note:
NAME 
Name
_name
_NAME
NAme123

all are different because python is a case-sensitive language.
that means A and a both are different.

last but not least
Rule 3:
There is no fixed length to define an identifier name  
that is example variable name can be written with any length but should be using some specific standards which can be used to understand by any other programmers and
readability of the code depends on this rule.

Hope you find useful
give a like and if you think if it is useful and also don't forget to share with your friends
If you have any doubts comment below or contact me.




No comments:

Post a Comment