None
: Represents null/empty value (e.g., x = None
)True
: Boolean true value (e.g., x = True
)False
: Boolean false value (e.g., x = False
)and
: Logical AND operator (e.g., if x > 0 and y > 0:
)or
: Logical OR operator (e.g., if x > 0 or y > 0:
)not
: Logical NOT operator (e.g., if not x
):in
: Membership test operator (e.g., if x in list:
)is
: Identity comparison (e.g., if x is None:
)if
: Conditional statement (e.g., if x > 0:
)elif
: Else if condition (e.g., elif x < 0:
)else
: Default condition (e.g., else:
)for
: For loop (e.g., for x in list:
)while
: While loop (e.g., while condition:
)break
: Exit loop (e.g., break
)continue
: Skip to next iteration (e.g., continue
)pass
: Null operation placeholder (e.g., pass
)try
: Begin exception handling block (e.g., try:
)except
: Handle specific exceptions (e.g., except ValueError:
)finally
: Always executed block (e.g., finally:
)raise
: Raise an exception (e.g., raise ValueError("Invalid input"
))assert
: Debug assertion (e.g., assert x > 0, "x must be positive"
)def
: Define function (e.g., def my_function(
):)class
: Define class (e.g., class MyClass:
)return
: Return value from function (e.g., return result
)yield
: Generator yield (e.g., yield value
)lambda
: Anonymous function (e.g., lambda x: x * 2
)global
: Declare global variable (e.g., global counter
)nonlocal
: Declare nonlocal variable (e.g., nonlocal outer_var
)import
: Import module (e.g., import math
)from
: Import specific items (e.g., from math import sqrt
)as
: Alias for imports (e.g., import numpy as np
)async
: Define async function (e.g., async def fetch_data(
):)await
: Wait for async operation (e.g., result = await fetch_data(
))del
: Delete object reference (e.g., del my_variable
)with
: Context manager (e.g., with open('file.txt') as f:
)