Identifiers in Python

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:

  1. The only allowed character in python are
  •   alphabet symbols(either lower case or upper case)
  •   digits(0 to 9)
  •   underscore symbol(_)
  By mistake if we are using any other symbol likes $ then we will get syntax error.
  • cash = 10
  • ca$h=20
  2. identifiers should start with digit
  • 123total
  • total123
 3. Identifiers are case sensitive. Of course Python language is case sensitive language.
  • total=10
  • TOTAL=999
  • print(total)#10
  • print(TOTAL)#999

Identifiers:

  1. Alphabet symbols should be (Either upper case or lower case)
  2. If identifiers starts with Underscore(_)then it indicates it is private.
  3. Identifiers should starts with digits.
  4. Identifiers are case sensitive.
  5. We can not use reserved words as identifiers.     Eg; def=10   #this is wrong
  6. There is no length limit for Python identifiers. but recommended to use  too lengthy identifiers.
  7. Dollor ($) symbol is not allowed in Python.

Q. Which are the following are the valid identifiers?

  1. 123total
  2. total23
  3. java2share
  4. ca$sh
  5. _abc_abc
  6. del
  7. if

Note:

  1. if identifiers starts with _symbol then it indicates it is private
  2. if identifiers starts with__(two underscore symbols)indicating that strongly private identifier.
  3. 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

Featured Post

Core and Advance Python

                      Language Fundamentals