pass — Advanced Examples
A no-op placeholder; does nothing, used where syntax requires a statement
Pass in metaclasses and decorators
Using pass in class construction patterns.
python
# Empty class as a namespace class Config: pass Config.debug = True Config.version = "1.0" Config.max_retries = 3 print(vars(Config)) # Pass in conditional class body def make_class(with_method): class Result: if with_method: def greet(self): return "Hello!" else: pass return Result WithGreet = make_class(True) WithoutGreet = make_class(False) print(WithGreet().greet()) print(hasattr(WithoutGreet(), "greet"))
pass is occasionally needed in dynamic class construction where conditional blocks in the class body might be empty.
Want to try these examples interactively?
Open Advanced Playground