Runtime Inspection Methods
code.co_lines()
Iterate bytecode offset ranges with source line numbers or None. Ranges are half-open and zero-width ranges can exist; introduced in Python 3.10.
Formal Syntax & Structure
python syntaxpython
code.co_lines()Return Value
iterator[tuple[int, int, int | None]]
Result of the inspection method.
Working Example
Example Snippetpython
def f(x): return x+1code = f.__code__ranges = list(code.co_lines())print((ranges[0][0],ranges[-1][1] == len(code.co_code)))