Language and Compiler Modules

dis

Inspects CPython bytecode instructions generated from functions and code objects. Useful for investigating compiler and interpreter behavior, but instruction names, offsets and specialization change across versions. Do not infer measured performance solely from instruction counts.

Formal Syntax & Structure

python syntaxpython
import dis

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import disdef add(a, b):    return a + bprint(any(i.opname == "BINARY_OP" for i in dis.get_instructions(add)))
Python Reference