is there a difference between one line and many lines

Chris Angelico rosuav at gmail.com
Thu Apr 21 12:02:52 CEST 2011


On Thu, Apr 21, 2011 at 7:55 PM, vino19 <vinograd19 at gmail.com> wrote:
> Sure, I understand that "is" is not "==", cause "is" just compares id(a)==id(b).
>
> I have a win32 CPython and the range of "singletons" is from -5 to 256 on my machine.
>
> I am asking about what happens in Python interpreter? Why is there a difference between running one line like "a=1;b=1" and two lines like "a=1 \n b=1"? Does it decide to locate memory in different types depend on a code?

Ah okay! In that case, I'm guessing this is going to be an oddity of
the IDLE system, because it's compiling each line separately. When you
put it on a single line, it's saving some trouble by sharing the
constant; when you do them separately, it doesn't optimize like that.

Chris Angelico



More information about the Python-list mailing list