$ python Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:53:06) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> a = (1, 2) >>> '%d %d %d' % (0, *a) '0 1 2' >>> '%d %d %d' % (*a, 3) '1 2 3' >>> '%d %d' % (*a) File "<stdin>", line 1 SyntaxError: can't use starred expression here >>>
My question, why?
In a more serious tone: I'd like an answer, or a reference, that details all the ins and outs of using a starred expression, as it happens that I am sometimes surprised from its behaviours...
To reflect some of the enlightening comments that immediately followed my question I add the following code
>>> '%d %d' % (, *a) File "<stdin>", line 1 '%d %d' % (, *a) ^ SyntaxError: invalid syntax >>> '%d %d' % (*a,) '1 2' >>>
(I had tried the
(, a) part before posting the original question but I've omitted it 'cause the error was not related to the starring.)
There is a syntax, in python ? 3.5, that "just works" but nevertheless I would like some understanding.