Python

Constant Folding in Python

PythonInternals & IntrospectionDis Moduleadvanced

What this snippet does

The Python compiler performs constant folding at compile time, replacing 2 * 3 with 6 in the bytecode.

Expected output

  2           0 RESUME                   0
              2 RETURN_CONST             1 (6)

Why practise typing this

Typing internals & introspection code builds muscle memory for the symbols and indentation Python uses most, which prose-based typing tests never cover. DevType measures your words per minute and accuracy on this snippet and tracks the individual characters you mistype, so later lessons can target them.

More Python practice

Browse all Python snippets →