A new to Python question

Steven Bethard steven.bethard at gmail.com
Sat May 14 16:46:58 EDT 2005


Steven Bethard wrote:
> 
> I don't know the implementation enough to know whether or not a tuple is 
> actually created when "b" and "c" are bound to their values, but I'd be 
> willing to bet that whatever happens to "(b, c)" is exactly the same as 
> what happens to "b, c".

Some corroborating evidence:

py> def f(t):
...     (b, c) = t
...
py> def g(t):
...     b, c = t
...
py> import dis
py> dis.dis(f)
   2           0 LOAD_FAST                0 (t)
               3 UNPACK_SEQUENCE          2
               6 STORE_FAST               2 (b)
               9 STORE_FAST               1 (c)
              12 LOAD_CONST               0 (None)
              15 RETURN_VALUE
py> dis.dis(g)
   2           0 LOAD_FAST                0 (t)
               3 UNPACK_SEQUENCE          2
               6 STORE_FAST               2 (b)
               9 STORE_FAST               1 (c)
              12 LOAD_CONST               0 (None)
              15 RETURN_VALUE

They're both an UNPACK_SEQUENCE byte-code.

STeVe



More information about the Python-list mailing list