Why tuple with one item is no tuple
Daniel Dittmar
daniel.dittmar at sap.corp
Wed Mar 16 11:08:35 EST 2005
Diez B. Roggisch wrote:
>>for instance I have written once somekind of vector class where
>>it was natural for these vectors to be added as well as te be
>>concatenated. Unfortunately python uses "+" for both so I had
>>no way to have both operators in a natural way in python.
>
>
> And no way in mathematics or any other language either - if you want the
> same function symbol on the same operators to have _different_ semantics,
> you're getting pretty non-deterministic.
>
I think he meant that Python should have introduced different operators
for addition and sequence concatenation.
> Your opinion is wrong. It's because you seem to not have understood the
> example: The expression (5 + 4) could be understood as 9 or as (9,). In
It should be understood as 9, but if integers etc implement the sequence
protocol, 9 can be used just like a tuple
(http://www.livejournal.com/users/glyf/29038.html).
There have been other proposals where you could write 'for i in 5' etc.
I find this 'creative use of overloading' rather awful. But what the
heck, I find list comprehension rather awful.
Daniel
More information about the Python-list
mailing list