Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: is there a difference between one line and many lines

Reply
Thread Tools

Re: is there a difference between one line and many lines

 
 
vino19
Guest
Posts: n/a
 
      04-21-2011
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?

Thanks
 
Reply With Quote
 
 
 
 
Heiko Wundram
Guest
Posts: n/a
 
      04-21-2011
Am 21.04.2011 11:55, schrieb vino19:
> 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?


There is no difference between the two.

You've not given the initializers for a/b in the two statement groups
you showed, so that what Chris Angelico said is probably what's
happening here (i.e.: in the first case, you stay in the singleton
range, in the second case which builds on the first, you don't).

--
--- Heiko.
 
Reply With Quote
 
 
 
 
Heiko Wundram
Guest
Posts: n/a
 
      04-21-2011
Am 21.04.2011 11:59, schrieb Heiko Wundram:
> Am 21.04.2011 11:55, schrieb vino19:
>> 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?

>
> There is no difference between the two.
> ...


Erm, sorry, forget my post. I misread a=-6 as a-=6, etc... So: what
Chris said. Anyway, there is semantically no difference between the two,
and that stands.

--
--- Heiko.
 
Reply With Quote
 
Jean-Michel Pichavant
Guest
Posts: n/a
 
      04-21-2011
vino19 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?
>
> Thanks
>

Probably, for optimisation purpose I guess. This is very implementation
specific and as a newby, you should not care about such trivial details.
The worst thing on earth you could do would be to code knowing that some
values are singleton and take profit from it. Well, maybe coding in perl
would be worse...

JM
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
is there a difference between one line and many lines vino19 Python 5 04-21-2011 02:16 PM
How to display a string in many lines, each lines have a specified length thuyptt@dsp.com.vn C++ 1 12-06-2005 07:26 AM
Asp.Net Calender, how to display 5 lines if there are only 5 lines in one month? Jack ASP .Net 9 10-12-2005 03:44 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM



Advertisments