About Identifiers in Python| #02 |
What is Identifier?
⇒ A Python identifier is a name of an Object.
⇒ An identifier is used to identify an object.
⇒ Objects can be Variables, Functions, Class, Module, and any other Object.
Python has some rules to give names as Identifiers.
⇒ Identifiers can contain only Alphabetic a to z, A to Z, Digits(0 to 9), and Underscore( _ )
For Example
(Here we denoted, Red for Invalid and Green For Valid Identifier)
⇨ car , Car , CAR , Bus , DEv , abc23 , a1b2 , lsky , _dev_shah , LSky_education123 etc.
⇒ Identifiers Should not start from the number(digits).
For Example
⇨ 1dev , 5434 , 434shah , 0car , 0_abc123 , etc.
⇒ Identifiers can not contain any white-space.
For Example
⇨ dev shah , LSky education , ab c , ab12cd efgh , xyz_2 abc , etc.
⇒ There are not allowed to use Symbolic Characters such as @, $, %, etc.
For Example
⇨ dev@shah , LSky$education , ab%c , @b12cdefgh , xyz_2!abc , abcd()xyz , abc~efg , etc.
(NOTE: if we use '#' symbol in side identifier's name like: abcd#xyz . It will generate NameError because In Python '#' symbol is used to write comments.)
⇒ There are not allowed to Operators Symbolic Characters such as ^, &, *, / , - , +, etc.
For Example
⇨ xyz%abc , xyz^abc , xyz&abc , xyz*abc , xyz-abc , xyz+abc , xyz\abc , xyz/abc , xyz:abc , etc.
⇒ Python is case sensitive programming language So, In Python identifiers ' car ' and ' Car ' are different identifiers.
For Example
Output:
this is first variable this is second variable this is Third variable
⇒ There is no length limit for Python identifiers. But not recommended to use too lengthy
identifiers.
⇒ Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
⇒ If Identifier is start with Single Underscore (_) then it indicates it is private.
For Example: _abc
⇒ If identifier starts with (Two Underscore Symbols) indicating that strongly private identifier.
For Example: __abc
⇒ If the identifier starts and also ends with two underscore symbols then the identifier is language defined special name, which is also known as magic methods.
For Example: __abc__
Comments
Post a Comment