import dis
defsimple():
return42defimplicit():
x = 42print("Explicit return:")
dis.dis(simple)
print("\nImplicit return (None):")
dis.dis(implicit)
# Return pushes value onto stack then RETURN_VALUE pops it# Implicit return adds LOAD_CONST None + RETURN_VALUE# Inspect return value behaviorprint(f"\nsimple() returns: {simple()}")
print(f"implicit() returns: {implicit()}")
print(f"implicit() is None: {implicit() is None}")
Output
Click "Run" to execute your code
Every function ends with RETURN_VALUE bytecode. Functions without explicit return get an implicit 'return None' — the compiler adds LOAD_CONST None before RETURN_VALUE.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?