defexample(x: int, y: str = "hello") -> bool:
"""An example function."""
z = x + len(y)
return z > 10import dis
import inspect
# Signature
sig = inspect.signature(example)
print(f"Signature: {sig}")
# Annotationsprint(f"Annotations: {example.__annotations__}")
# Code object
code = example.__code__
print(f"Variables: {code.co_varnames}")
print(f"Constants: {code.co_consts}")
# Bytecodeprint(f"\nBytecode:")
dis.dis(example)
Output
Click "Run" to execute your code
Functions are first-class objects with rich metadata: __code__ holds the compiled bytecode, __annotations__ holds type hints, and __doc__ holds the docstring. The dis module shows the bytecode instructions.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?