import dis
defwith_pass():
passdefwithout_pass():
returnNoneprint("pass bytecode:")
dis.dis(with_pass)
print("\nexplicit return None:")
dis.dis(without_pass)
# pass compiles to exactly nothing — it generates# no bytecode at all. The function still needs# LOAD_CONST None + RETURN_VALUE for the implicit return.print(f"\npass code size: {len(with_pass.__code__.co_code)}")
print(f"return None code size: {len(without_pass.__code__.co_code)}")
Output
Click "Run" to execute your code
pass generates zero bytecode instructions. The only bytecode in a pass-only function is the implicit 'return None' that every function gets.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?