Glossary

Bytecode

Bytecode is the low-level, platform-independent set of instructions that CPython compiles Python source code into before execution. Each bytecode instruction is a simple operation — load a value, call a function, jump to an offset — that the Python virtual machine can execute efficiently. Bytecode files are cached in __pycache__/ directories with .pyc extensions, keyed to the Python version, so unchanged modules skip the compilation step on subsequent imports.

You can inspect bytecode using the dis module in the standard library. Running dis.dis(some_function) prints a human-readable disassembly showing each instruction, its arguments, and the corresponding source line number. This is invaluable for understanding performance characteristics and what Python actually does with your code at a low level.

Bytecode is an implementation detail of CPython, not part of the Python language specification. Other implementations may use different intermediate representations: PyPy has its own trace-based JIT compiler, and Jython compiles to Java bytecode. The bytecode format changes between CPython versions, which is why .pyc files include the version tag and should never be committed to version control.

Related terms: CPython, Interpreter

Discussed in:

This site is currently in Beta. Please email Chris Paton (cpaton@gmail.com) with any suggestions, questions or comments.