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

Discussion in 'Python' started by vino19, Apr 21, 2011.

  1. vino19

    vino19 Guest

    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
     
    vino19, Apr 21, 2011
    #1
    1. Advertising

  2. 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.
     
    Heiko Wundram, Apr 21, 2011
    #2
    1. Advertising

  3. 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.
     
    Heiko Wundram, Apr 21, 2011
    #3
  4. 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
     
    Jean-Michel Pichavant, Apr 21, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,279
  2. Jack
    Replies:
    9
    Views:
    2,691
  3. Replies:
    1
    Views:
    463
    Jonathan Mcdougall
    Dec 6, 2005
  4. vino19
    Replies:
    5
    Views:
    214
    Westley Martínez
    Apr 21, 2011
  5. Peter Otten
    Replies:
    0
    Views:
    181
    Peter Otten
    Jan 17, 2013
Loading...

Share This Page