Python, Tutorials

Identifiers in Python

Python keywords cannot be used as entity names. The name given to a variable, class, or function in Python is called an identifier. But there are some rules for writing identifiers.

Rules for a valid identifier name

  1. A keyword cannot be used as an identifier.
  2. An identifier can be in lowercase, uppercase, digits, or the combination of all three. Underscore (_) is also valid.
  3. An identifier cannot begin with a digit. The first character should be an alphabet (uppercase or lowercase) or an underscore.
  4. Symbols such as #, $, %, @, etc cannot be used in identifiers

There is no length limit for identifiers in Python.

Example of Valid Identifier in python

  • variable1
  • MyVariable
  • _variable
  • Class1
  • class2
  • function1
  • Function2

Examples of Invalid Identifier in python

  • 1variable
  • 2Class
  • variable$
  • function##

Thank you for reading, Happy Learning, drop your suggestion in the comments.

Feel free to follow us on Youtube , Linked In , Instagram

0 0 vote
Article Rating