Python "is" behavior

"Martin v. Löwis" martin at
Sat Jun 21 18:14:08 CEST 2008

> For some reason, stacking multiple statements reuses the same object.

Each code object has a co_consts tuple referring to all constants used
in the code. The compiler interns duplicate constants for a single
compiler run, resulting in the same object being used when the code
is put into a single line (or in a function, or module).

When the code is split into multiple interactive statements, the
compiler runs multiple times, and doesn't know anything about past


More information about the Python-list mailing list