pyguides

Reference

Keywords

Python Keywords reference.

  1. := (walrus operator)

    The walrus operator := assigns values to variables as part of an expression

  2. and

    The and keyword performs logical conjunction, returning True only if both operands are truthy

  3. as keyword

    The as keyword creates aliases for imports, captures exceptions, and binds context managers

  4. assert

    The assert statement checks conditions during development and raises AssertionError if the condition is false

  5. async/await

    The async and await keywords enable asynchronous programming, allowing non-blocking execution of coroutines

  6. await

    Suspend an async function until an awaitable completes, yielding control to the event loop.

  7. break

    The break statement immediately exits the nearest enclosing loop in Python

  8. class

    The class keyword defines a new class in Python, creating objects that serve as blueprints for objects

  9. continue

    The continue statement skips the rest of the current loop iteration and proceeds to the next one

  10. def

    The def keyword defines functions in Python, creating reusable blocks of code with optional parameters and return values

  11. del

    The del statement removes variables, list items, dictionary entries, or object attributes in Python

  12. elif / else

    Chain conditional tests with elif, or define fallback and secondary behaviour with else on if, try, for, and while.

  13. elif / else

    The elif and else keywords create conditional branches in Python, allowing you to handle multiple conditions

  14. for

    The for keyword iterates over sequences in Python, looping through items in lists, strings, ranges, and other iterables

  15. from

    The from statement imports specific names from a module in Python, allowing you to use imported names directly without the module prefix

  16. global

    The global keyword lets you declare that a variable inside a function refers to the module-level variable

  17. if statement

    The if keyword is used for conditional execution in Python, executing code blocks based on boolean conditions

  18. in operator

    The in keyword checks membership in sequences, strings, and collections in Python

  19. is operator

    The is operator checks object identity in Python, comparing whether two variables reference the same object in memory

  20. lambda

    The lambda keyword creates anonymous inline functions in Python, useful for short-lived operations without full function definitions

  21. nonlocal

    The nonlocal keyword lets you modify variables in an enclosing (non-global) function scope

  22. not

    The not keyword performs logical negation, inverting the truthiness of its operand

  23. or operator

    The or keyword performs logical disjunction, returning the first truthy operand or the last falsy one

  24. pass

    The pass keyword is a null operation used as a placeholder in empty code blocks

  25. raise

    The raise statement explicitly triggers an exception in Python, signaling errors and controlling program flow

  26. return

    The return keyword exits a function and optionally passes a value back to the caller

  27. try / except / finally

    The try, except, and finally statements handle exceptions and ensure cleanup code runs in Python

  28. try / except / finally

    Handle exceptions in Python with try, except, else, and finally blocks. Covers exception types, raising, chaining, and exception groups.

  29. while

    Executes a block of code repeatedly while a condition remains true.

  30. with

    The with statement in Python provides context management, ensuring resources are properly acquired and released

  31. yield

    The yield keyword in Python creates generator functions, producing values lazily without building full lists in memory