bad operand type for unary +: tuple

Frank Millman frank at
Thu Oct 22 11:59:21 CEST 2009

Hi all

This is just out of curiosity.

I have a tuple, and I want to create a new tuple with a new value in the 
first position, and everything else unchanged.

I figured out that this would work -

>>> t = ('a', 'b', 'c')
>>> t2 = ('x',) + t[1:]
>>> t2
('x', 'b', 'c')

Then I thought I would neaten it a bit by replacing "('x',)" with "'x'," on 
the assumption that it is not necessary to surround a tuple with brackets.

This is the result -

>>> t = ('a', 'b', 'c')
>>> t2 = 'x', + t[1:]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: bad operand type for unary +: 'tuple'

It is not a problem - I will just stick to using the brackets. However, I 
would be interested to find out the reason for the error.

Version is 2.6.2.


Frank Millman

More information about the Python-list mailing list