Python Glossary Русский

all Python 3typesterm

types.CodeType

interpreter objects

The type of compiled bytecode: what func.__code__ holds and what compile() returns. It stores variable names, constants and the argument count.

Syntax

func.__code__

__code__ shows what the signature hides: co_varnames lists the parameters first and then the local variables, while co_argcount counts positional ones only. A code object is immutable and knows nothing of defaults or the closure — those live in the function. Do not build one with the constructor: its arguments change between Python versions; use code.replace(...) instead. To read a signature, inspect.signature is easier.

Examples

def area(w, h=1):
    s = w * h
    return s
code = area.__code__
print(code.co_varnames, code.co_argcount)  # → ('w', 'h', 's') 2
print(type(code).__name__)  # → code

See also

Open in the full glossarydocs.python.orgReport an inaccuracy