Why tuple with one item is no tuple

Diez B. Roggisch deetsNOSPAM at web.de
Wed Mar 16 08:17:49 EST 2005


>> Consider this:
>>     a = (3 + 5) * 5
>> You really, really want (3 + 5) to be an integer, not a one-item tuple. 
> 
> I sometimes do wonder if some impliciteness wouldn't be better here,
> so that any item could be treated as if it was a one-item tuple.
> 
> A bit like every char being a string.

There is no char. There are strings of lenght 1. And the above example makes
it clear that there would be an ambiguity that could _maybe_ be solved in a
static typed language (the application of the (3+5) as left side to the
operator <*> if <*> only is defined as [num, num] -> num), but clearly not
in a dynamic typed one as python.

And if the static typed language allows operator overloading, it could very
well be that someone creates a overloading for 

<*> : [tuple[num], tuple[num]] -> <whatever>

which would reintroduce the ambiguity.

Soooooo, in the end it boils down to some explicitness - where IMHO an
additional comma is pretty much no problem at all. Another option would of
course be the introduction of different parentheses for tuples - but I
can't find some on my keyboard.

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list