pass — Advanced Playground
A no-op placeholder; does nothing, used where syntax requires a statement
Python Playground
# 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"))
Output
Click "Run" to execute your code
pass is occasionally needed in dynamic class construction where conditional blocks in the class body might be empty.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?