Identifier and keywords in python


An Identifier

     An identifier is a name given to program elements such as variable,classes and functions etc.
    An identifier is a sequence of letters, digits and underscore, the first character of which can not be a digit.

  Example:-       number=10  ,                 here a variable name(number) is an identifier.
                          def factorial (n)  ,           here a function name(factorial) is an identifier.
                          class recur    ,                  here a class name(recur) is an identifier.

    Following rules must be follow while naming an identifier :-

  • The first character must be an alphabet (uppercase or lowercase) or can be an underscore.
  • An identifier can not start with a digit.
  • No special characters like @, &,$,#,% etc. is allowed except the underscore.
  • No two successive ( _ ) underscore are allowed.
  • Keywords can not be used as an identifiers.

Python Keywords

        Python keywords are set words that cannot be used as an identifier in program.
       These words are known as "reserved words" or "keywords".


There are some available keywords in python programming language:-


    Keywords                            Description

  • class                                                     Used to define a class.
  • try                                                         Used in Exception Handling.
  • catch                                                    Used in Exception Handling.
  • finally                                                   Used in Exception Handling.
  • and                                                       Used as a logical operators.
  • or                                                          Used as a logical operators.
  • not                                                        Used as a logical operators.
  • if                                                           Used in conditional statements.
  • else                                                      Used in conditional statements.
  • elif                                                        Used in conditional statements.
  • print                                                     Used to print the element of python
  • import                                                  Used to import the packages.
  • break                                                    Used in looping statements.
  • continue                                              Used in looping statements.
  • for                                                        Used in looping statements.
  • while                                                    Used in looping statements.
  • return                                                   Used to return a value.
  • etc.


No comments:

Post a Comment