python tutorial - Python Identifier - learn python - python programming




 identifiers in python
  • A Python identifier is a name used to identify a variable, function, class, module or other object.
  • An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9).
  • Identifiers are the names given to the fundamental building blocks in a program.
  • These can be variables, class, object, functions, lists, dictionaries etc.
  • There are certain rules defined for naming i.e., Identifiers.
  1. An identifier is a long sequence of characters and numbers.
  2. No special character except underscore ( _ ) can be used as an identifier.
  3. Keyword should not be used as an identifier name.
  4. Python is case sensitive. So using case is significant.
  5. First character of an identifier can be character, underscore ( _ ) but not digit.
  • Examples of valid identifier names are i, __my_name, name_23 and a1b2_c3.
  • Examples of invalid identifier names are 2things, this is spaced out and my-name.

Rules for writing identifiers:

  • 1. Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore (_). Names like myClass, var_1 and print_this_to_screen, all are valid example.
  • 2. An identifier cannot start with a digit. 1variable is invalid, but variable1 is perfectly fine.
  • Keywords cannot be used as identifiers.
>>> global = 1
  File "<interactive input>", line 1
    global = 1
	         ^
Syntax Error: invalid syntax
click below button to copy the code. By Python tutorial team
  • We cannot use special symbols like !, @, #, $, % etc. in our identifier.
>>> [email protected] = 0
  File "<interactive input>", line 1
    [email protected] = 0
     ^
Syntax Error: invalid syntax
click below button to copy the code. By Python tutorial team
  • Identifier can be of any length.

Wikitechy tutorial site provides you all the learn python , python cursus online , python programming course free , where to learn python programming , free online python course , online free python course , learn python coding online , python developers , python certification free , python learning course , online course python

Related Searches to Python Identifier