passIntermediate Examples

A no-op placeholder; does nothing, used where syntax requires a statement

Pass in exception handling

Using pass to silently ignore specific exceptions.

python
# Silently ignore specific errors
import os

# Try multiple operations, skip failures
operations = [
    lambda: int("42"),
    lambda: int("hello"),
    lambda: 1 / 0,
    lambda: int("99"),
]

results = []
for op in operations:
    try:
        results.append(op())
    except (ValueError, ZeroDivisionError):
        pass

print(f"Successful results: {results}")

# Abstract base pattern (before ABC)
class Shape:
    def area(self):
        raise NotImplementedError

class Circle(Shape):
    def __init__(self, r):
        self.r = r
    def area(self):
        return 3.14159 * self.r ** 2

print(Circle(5).area())
Expected Output
Successful results: [42, 99]
78.53975

pass in except blocks silently swallows exceptions. Use this sparingly — usually you should at least log the error.

Pass vs ellipsis

Comparing pass with ... as a placeholder.

python
# pass: traditional placeholder
class MyClass:
    pass

# Ellipsis: modern typing placeholder
def process(data: list[int]) -> list[int]:
    ...

# Both work, but convention differs:
# - pass: syntactic placeholder in any block
# - ...: type stub / protocol placeholder

from typing import Protocol

class Drawable(Protocol):
    def draw(self) -> None: ...

print("pass type:", type(pass if False else None))
print("... type:", type(...))
print("... value:", ...)

pass is a statement that does nothing. Ellipsis (...) is an object often used as a placeholder in type stubs and abstract methods.

Want to try these examples interactively?

Open Intermediate Playground