Runtime Data Attributes

code.co_nlocals

Number of local variable slots represented by the code object, including parameters. This is compiled metadata, not the number of currently bound local names.

Formal Syntax & Structure

python syntaxpython
code.co_nlocals

Return Value

int

Value exposed by this attribute; availability and mutability depend on the owner as described.

Working Example

Example Snippetpython
def f(a):    b = a+1    return bcode = f.__code__print(code.co_nlocals)
Python Reference