Editor

Disassemble a Function

Advanced · Write the code · from How Python Works Under the Hood: Memory, GIL, and Bytecode

From the lesson: How Python Works Under the Hood: Memory, GIL, and Bytecode

Every time you type x = 42, a lot happens behind the scenes. Python creates an integer object in memory, assigns a reference to it, and manages its lifecycle automatically. Understanding these internals doesn't just satisfy curiosity -- it helps you write faster code, debug memory issues, and nail technical interviews.

Read the lesson

Write a function called multiply(a, b) that returns a * b. Then use dis.get_instructions() to inspect its bytecode and collect the instruction names (opnames) into a set.

Print whether the bytecode contains 'BINARY_OP' (the multiplication step) and whether it contains 'RETURN_VALUE' (the return step), then print Done.

We check for specific opnames instead of printing the full disassembly because the exact bytecode listing differs between Python versions.

import dis
# Define multiply, then inspect its bytecode

More Internals exercises

All Python exercises · 50 practice problems · Advanced Python quiz