is there a difference between one line and many lines

Daniel Kluev dan.kluev at gmail.com
Thu Apr 21 06:17:24 EDT 2011


On Thu, Apr 21, 2011 at 8:38 PM, vino19 <vinograd19 at gmail.com> wrote:
> Hello, I'm a newbie.
> What's the defference between
>*skip*

What is version of CPython?
In 2.7.1 and 3.1.3 both versions return True, and moreover, are
compiled to identical bytecode.
>>> def test1():
... a=-6; b=-6; c = a is b
... return c
>>> def test3():
... a=-6
... b=-6
... c = a is b
... return c
>>> test1()
True
>>> test3()
True
>>> dis.dis(test1)
 2 0 LOAD_CONST 1 (-6)
 3 STORE_FAST 0 (a)
 6 LOAD_CONST 1 (-6)
 9 STORE_FAST 1 (b)
 12 LOAD_FAST 0 (a)
 15 LOAD_FAST 1 (b)
 18 COMPARE_OP 8 (is)
 21 STORE_FAST 2 (c)
 3 24 LOAD_FAST 2 (c)
 27 RETURN_VALUE
>>> dis.dis(test3)
 2 0 LOAD_CONST 1 (-6)
 3 STORE_FAST 0 (a)
 3 6 LOAD_CONST 1 (-6)
 9 STORE_FAST 1 (b)
 4 12 LOAD_FAST 0 (a)
 15 LOAD_FAST 1 (b)
 18 COMPARE_OP 8 (is)
 21 STORE_FAST 2 (c)
 5 24 LOAD_FAST 2 (c)
 27 RETURN_VALUE
So AFAIK, there is no difference for interpreter itself, its purely
syntactic, and is compiled to exactly same bytecode.
-- 
With best regards,
Daniel Kluev


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /