Definition:
A name in Python program is called identifiers.
It can be class name or function name or module name or variable name.
a=10
Rules to define identifiers in Python:
- The only allowed character in python are
- alphabet symbols(either lower case or upper case)
- digits(0 to 9)
- underscore symbol(_)
- cash = 10
ca$h=20
123total- total123
- total=10
- TOTAL=999
- print(total)#10
- print(TOTAL)#999
Identifiers:
- Alphabet symbols should be (Either upper case or lower case)
- If identifiers starts with Underscore(_)then it indicates it is private.
- Identifiers should starts with digits.
- Identifiers are case sensitive.
- We can not use reserved words as identifiers. Eg;
def=10#this is wrong - There is no length limit for Python identifiers. but recommended to use too lengthy identifiers.
- Dollor ($) symbol is not allowed in Python.
Q. Which are the following are the valid identifiers?
123total- total23
- java2share
ca$sh- _abc_abc
delif
Note:
- if identifiers starts with _symbol then it indicates it is private
- if identifiers starts with__(two underscore symbols)indicating that strongly private identifier.
- if the identifiers starts and ends with two underscore symbols then the identifier is language defined special name,which is also known as magic method Eg: __add__
No comments:
Post a Comment