keywords
Python keywords reference.
:= (walrus operator)
The walrus operator := assigns values to variables as part of an expression
and
The and keyword performs logical conjunction, returning True only if both operands are truthy
as keyword
The as keyword creates aliases for imports, captures exceptions, and binds context managers
assert
The assert statement checks conditions during development and raises AssertionError if the condition is false
async/await
The async and await keywords enable asynchronous programming, allowing non-blocking execution of coroutines
await
Suspend an async function until an awaitable completes, yielding control to the event loop.
break
The break statement immediately exits the nearest enclosing loop in Python
class
The class keyword defines a new class in Python, creating objects that serve as blueprints for objects
continue
The continue statement skips the rest of the current loop iteration and proceeds to the next one
def
The def keyword defines functions in Python, creating reusable blocks of code with optional parameters and return values
del
The del statement removes variables, list items, dictionary entries, or object attributes in Python
elif / else
Chain conditional tests with elif, or define fallback and secondary behaviour with else on if, try, for, and while.
elif / else
The elif and else keywords create conditional branches in Python, allowing you to handle multiple conditions
for
The for keyword iterates over sequences in Python, looping through items in lists, strings, ranges, and other iterables
from
The from statement imports specific names from a module in Python, allowing you to use imported names directly without the module prefix
global
The global keyword lets you declare that a variable inside a function refers to the module-level variable
if statement
The if keyword is used for conditional execution in Python, executing code blocks based on boolean conditions
in operator
The in keyword checks membership in sequences, strings, and collections in Python
is operator
The is operator checks object identity in Python, comparing whether two variables reference the same object in memory
lambda
The lambda keyword creates anonymous inline functions in Python, useful for short-lived operations without full function definitions
nonlocal
The nonlocal keyword lets you modify variables in an enclosing (non-global) function scope
not
The not keyword performs logical negation, inverting the truthiness of its operand
or operator
The or keyword performs logical disjunction, returning the first truthy operand or the last falsy one
pass
The pass keyword is a null operation used as a placeholder in empty code blocks
raise
The raise statement explicitly triggers an exception in Python, signaling errors and controlling program flow
return
The return keyword exits a function and optionally passes a value back to the caller
try / except / finally
The try, except, and finally statements handle exceptions and ensure cleanup code runs in Python
try / except / finally
Handle exceptions in Python with try, except, else, and finally blocks. Covers exception types, raising, chaining, and exception groups.
while
The while keyword executes a block of code repeatedly as long as a condition is true
with
The with statement in Python provides context management, ensuring resources are properly acquired and released
yield
The yield keyword in Python creates generator functions, producing values lazily without building full lists in memory