Optimisation problem
Skip Montanaro
skip at pobox.com
Tue Nov 12 13:55:25 EST 2002
gabor> x,y = 2,4
gabor> creates a tuple?
gabor> i thought thatr x,y=2,4 is the same as x=2;y=4
Semantically, yes, it's the same, however, it makes an intermediate tuple of
the rhs in the process of performing the assignment. The "dis" module is
your friend here:
>>> import dis
>>> def f(a,b):
... c,d = a,b
...
>>> dis.dis(f)
2 0 LOAD_FAST 0 (a)
3 LOAD_FAST 1 (b)
6 BUILD_TUPLE 2
9 UNPACK_SEQUENCE 2
12 STORE_FAST 2 (c)
15 STORE_FAST 3 (d)
18 LOAD_CONST 0 (None)
21 RETURN_VALUE
--
Skip Montanaro - skip at pobox.com
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list