bad operand type for unary +: tuple

Frank Millman frank at chagford.com
Thu Oct 22 09:36:26 EDT 2009


Diez B. Roggisch wrote:
> Frank Millman wrote:
>
>>
>>>>> 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'
>>>>>
>>

>
> the operator precedence. Sure you want to write
>
> (a, -b, c)
>
> to form a tuple with a negated (or actually all other kinds of 
> expressions)
> value in it. So python made -/+ and more or less all other operators
> precede the comma, which is the actual tuple-operator. And consequently,
>
> a, +(c, d)
>
> tries to *first* apply + to the tuple (c, d) - which isn't defined.
>

Makes total sense. Thanks, Diez

Frank






More information about the Python-list mailing list