Python - Identifiers

Identifiers are the names given to different entities such as variable name, class name, function name, etc.

Rules for naming Python identifiers

  1. An identifier can contain small letters (a – z), capital letters (A – Z), an underscore (_), and digits (0 to 9).
  2. An identifier must begin with letter, underscore but not with a digit.
  3. Python does not allow punctuation, special characters such as @, $, and % within identifiers.
  4. Python is a case sensitive programming language. Thus, FirstNumber and firstnumber are two different identifiers in Python.
  5. Class names start with an uppercase letter.
  6. Starting an identifier with a single leading underscore indicates that the identifier is private.
  7. Starting an identifier with two leading underscores indicates a strongly private identifier.
  8. If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
  9. A keyword cannot be used as an identifier.