• Home
  • LLMs
  • Docker
  • Kubernetes
  • Java
  • Python
  • Ubuntu
  • Maven
  • Archived
  • About
Python | Keywords
  1. Notes
  2. Literal Keywords
  3. Logical Operators
  4. Control Flow Keywords
  5. Exception Handling
  6. Function and Class Definition
  7. Scope and Import Keywords
  8. Async/Await Keywords
  9. Deletion
  10. Context Management

  1. Notes
    Python will throw a SyntaxError if you use any of the following keywords as a variable name.

    See this page for more details: https://docs.python.org/3/reference/lexical_analysis.html#keywords.
  2. Literal Keywords
    • None: Represents null/empty value (x = None)

    • True: Boolean true value (x = True)

    • False: Boolean false value (x = False)
  3. Logical Operators
    • and: Logical AND operator (if x > 0 and y > 0:)

    • or: Logical OR operator (if x > 0 or y > 0:)

    • not: Logical NOT operator (if not x):

    • in: Membership test operator (if x in list:)

    • is: Identity comparison (if x is None:)
  4. Control Flow Keywords
    • if: Conditional statement (if x > 0:)

    • elif: Else if condition (elif x < 0:)

    • else: Default condition (else:)

    • for: For loop (for x in list:)

    • while: While loop (while condition:)

    • break: Exit loop (break)

    • continue: Skip to next iteration (continue)

    • pass: Null operation placeholder (pass)
  5. Exception Handling
    • try: Begin exception handling block (try:)

    • except: Handle specific exceptions (except ValueError:)

    • finally: Always executed block (finally:)

    • raise: Raise an exception (raise ValueError("Invalid input"))

    • assert: Debug assertion (assert x > 0, "x must be positive")
  6. Function and Class Definition
    • def: Define function (def my_function():)

    • class: Define class (class MyClass:)

    • return: Return value from function (return result)

    • yield: Generator yield (yield value)

    • lambda: Anonymous function (lambda x: x * 2)
  7. Scope and Import Keywords
    • global: Declare global variable (global counter)

    • nonlocal: Declare nonlocal variable (nonlocal outer_var)

    • import: Import module (import math)

    • from: Import specific items (from math import sqrt)

    • as: Alias for imports (import numpy as np)
  8. Async/Await Keywords
    • async: Define async function (async def fetch_data():)

    • await: Wait for async operation (result = await fetch_data())
  9. Deletion
    • del: Delete object reference (del my_variable)
  10. Context Management
    • with: Context manager (with open('file.txt') as f:)
© 2025  mtitek