Because Python enforces indentation to define blocks, you cannot leave a function, class, or conditional statement completely empty. If you do, Python's parser raises an IndentationError: expected an indented block. The pass statement is a special syntactic null operation (no-op) that does nothing when executed, serving as an explicit placeholder for future implementation.
# Stubbing out an empty function for future implementation:
def process_payment_gateway(order_id: str):
pass # TODO: Integrate Razorpay/Stripe API tomorrow
# Creating an empty custom exception class:
class DatabaseConnectionError(Exception):
pass
# Creating an empty interface:
class AbstractReport:
pass
import os
# Safely delete a temporary file if it exists, ignoring missing file errors:
try:
os.remove("temporary_cache.txt")
except FileNotFoundError:
pass # Silently ignore if file already deleted
| Statement | What It Does When Encountered |
|---|---|
break | Terminates the loop completely and exits immediately. |
continue | Skips the remainder of the current iteration and jumps to the next iteration. |
pass | Does nothing at all. Continues execution of subsequent lines uninterrupted. |
...)In modern Python (especially in type hints and abstract class definitions), you can use the built-in Ellipsis literal (...) interchangeably with pass:
def fetch_user_profile(user_id: int):
...
IndentationError. You must use pass or ....