Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Python

Python Keywords and Identifiers: Mastering Reserved Words and Naming Conventions

Python Keywords and Identifiers

Learn Python’s 33 reserved words and how to give clear, meaningful names to variables, functions, and classes.

Python Keywords

Python keywords are the building blocks of the language’s syntax. They are reserved words that cannot be used as identifiers such as variable or function names. Because they define the language’s structure, using a keyword incorrectly results in a syntax error.

Keywords are case‑sensitive and are listed exactly as they appear in the language. In Python 3.7 there are 33 of them, though newer releases may add a few more. For a definitive reference, see the official Python documentation.

All keywords are lowercase except True, False, and None. The table below lists each keyword with a brief example of its typical use.

Falseawaitelseimportpass
Nonebreakexceptinraise
Trueclassfinallyisreturn
andcontinueforlambdatry
asdeffromnonlocalwhile
assertdelglobalnotwith
asyncelififoryield

While it may feel daunting to remember all 33 keywords, understanding their purpose is essential for writing clear, error‑free code.


Python Identifiers

An identifier is the name you give to classes, functions, variables, and other objects. It serves as a unique label that makes your code readable and maintainable.

Rules for Writing Identifiers

  1. Identifiers may contain letters (a–z, A–Z), digits (0–9), and the underscore _. Valid examples include myClass, var_1, and print_this_to_screen.
  2. They cannot begin with a digit; 1variable is invalid, whereas variable1 is acceptable.
  3. Keywords cannot be used as identifiers.
    global = 1
    Output
      File "<interactive input>", line 1
        global = 1
               ^
    SyntaxError: invalid syntax
  4. Special symbols such as !, @, #, $, %, etc., are not allowed.
    a@ = 0
    Output
      File "<interactive input>", line 1
        a@ = 0
         ^
    SyntaxError: invalid syntax
  5. There is no practical limit to the length of an identifier.

Things to Remember

Python is case‑sensitive, so Variable and variable refer to different objects.

Choose descriptive names: c = 10 is syntactically correct, but count = 10 conveys intent more clearly and eases future maintenance.

For multi‑word identifiers, the underscore _ is the recommended separator, e.g., this_is_a_long_variable. Adhering to PEP 8 naming conventions further enhances code readability.


Python

  1. Understanding C# Keywords and Identifiers: Rules, Lists, and Best Practices
  2. C Keywords & Identifiers: A Practical Guide
  3. Python Statements, Indentation, and Comments: A Clear Guide
  4. Python Namespaces & Variable Scope: Understanding Names, Bindings, and Scopes
  5. Mastering Python Loop Control: break & continue
  6. Mastering Directory and File Operations in Python
  7. Python Regular Expressions (re Module) – A Practical Guide
  8. Mastering Python's strftime(): Convert Dates and Times to Readable Strings
  9. Master Python's strptime() for Accurate Date Parsing
  10. Mastering Python’s time Module: Functions, Structs, and Practical Examples