pass — Intermediate Playground
A no-op placeholder; does nothing, used where syntax requires a statement
Python Playground
# 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())
Output
Click "Run" to execute your code
pass in except blocks silently swallows exceptions. Use this sparingly — usually you should at least log the error.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?