= Code object
In <CPython>, a <code object> represents compiled executable Python code. It stores <bytecode> and metadata such as constants, referenced names and source positions. A <function object> additionally supplies the global namespace, default argument values and, when needed, a <closure (computer programming)>[closure] connecting free variables to captured values. A code object by itself does not contain that execution context.<Python 3.14 Data Model>[§3.2.13.1, Code objects]{ref}
For example, calling a <function> factory twice can create two <function>[functions] with the same code object but different captured values. Their behavior differs because their <closure (computer programming)>[closures] differ, even though their <machine instruction>[instructions] are shared. Inspecting `f.__code__` therefore describes executable structure rather than a complete snapshot of `f`'s environment. Python documents code objects as immutable; version-specific <bytecode> details should not be treated as a permanent cross-version file format.
Back to article page