This is because it is:
(a)
This is just a value surrounded by parentheses. This is not a new tuple object. So your expression:
>>> '%d %d' % (*a)
will be translated into:
>>> '%d %d' % *a
which is clearly incorrect in terms of python syntax.
To create a new Tuple, with one expression as an initializer, you need to add a ' , ' after it:
>>> '%d %d' % (*a,)
Also, if I can offer something: you can start using formatting expressions of a new style. They are gorgeous!
>>> "{} {}".format(*a)
You can learn more about them in the t w o paragraphs of the python documentation, this excellent site is also there. The line above uses the argument unpacking mechanism described below.
Flagged Expressions
There are many other uses for a highlighted expression than just creating a new list / tuple / dictionary. Most of them are described in this PEP and this
They all come down to two types:
Unpacking RValue:
>>> a, *b, c = range(5) # a = 0 # b = [1, 2, 3] # c = 4 >>> 10, *range(2) (10, 0, 1)
Iterary / dictionary initialization of an object (note that you can also unzip dictionaries inside lists!):
>>> [1, 2, *[3, 4], *[5], *(6, 7)] [1, 2, 3, 4, 5, 6, 7] >>> (1, *[2, 3], *{"a": 1}) (1, 2, 3, 'a') >>> {"a": 1, **{"b": 2, "c": 3}, **{"c": "new 3", "d": 4}} {'a': 1, 'b': 2, 'c': 'new 3', 'd': 4}
Of course, the most common use is unpacking the arguments:
positional_arguments = [12, "a string", (1, 2, 3), other_object] keyword_arguments = {"hostname": "localhost", "port": 8080} send(*positional_arguments, **keyword_arguments)
which translates as follows:
send(12, "a string", (1, 2, 3), other_object, hostname="localhost", port=8080)
This section has already been covered to a large extent in another overflow of the question stack.