Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>so <a href="http://www.python.org/dev/peps/pep-3113/" rel="nofollow">pep 3113</a>, as artur gaspar points out, contains a full answer. It also lists a whole bunch of reasons why this probably isn't a great pattern to follow. One of these you discovered in the annoying side effects of debugging. A bigger one is I think that your code will break transitioning to python3, but I'm not sure/still am on 2.7 personally.</p> <p>I wanted to play with what happens. Looking as some disassembled bytecodes we can see what happens with these three functions (spoiler: foo and bar have identical bytecodes):</p> <pre><code>from dis import dis def foo(a, (b, c) ,d): return a + b + c + d def bar(a, b_c, d): b, c = b_c return a + b + c + d def baz(a, b, c, d): return a + b + c + d print '\nfoo:' dis(foo) print '\nbar:' dis(bar) print '\nbaz:' dis(baz) </code></pre> <p>Yields:</p> <pre><code>foo: 3 0 LOAD_FAST 1 (.1) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 3 (b) 9 STORE_FAST 4 (c) 4 12 LOAD_FAST 0 (a) 15 LOAD_FAST 3 (b) 18 BINARY_ADD 19 LOAD_FAST 4 (c) 22 BINARY_ADD 23 LOAD_FAST 2 (d) 26 BINARY_ADD 27 RETURN_VALUE bar: 7 0 LOAD_FAST 1 (b_c) 3 UNPACK_SEQUENCE 2 6 STORE_FAST 3 (b) 9 STORE_FAST 4 (c) 8 12 LOAD_FAST 0 (a) 15 LOAD_FAST 3 (b) 18 BINARY_ADD 19 LOAD_FAST 4 (c) 22 BINARY_ADD 23 LOAD_FAST 2 (d) 26 BINARY_ADD 27 RETURN_VALUE baz: 11 0 LOAD_FAST 0 (a) 3 LOAD_FAST 1 (b) 6 BINARY_ADD 7 LOAD_FAST 2 (c) 10 BINARY_ADD 11 LOAD_FAST 3 (d) 14 BINARY_ADD 15 RETURN_VALUE </code></pre> <p>As you can see. <code>foo</code> and <code>bar</code> are identical, while <code>baz</code> skips the unpacking. So yes, this will affect performance a bit, but only as long as tuple unpacking takes, which should be negligible in everything except very small functions and toy examples (like this one ;P)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload