Why tuple with one item is no tuple

Antoon Pardon apardon at forel.vub.ac.be
Wed Mar 16 07:56:51 EST 2005


Op 2005-03-16, Tim Roberts schreef <timr at probo.com>:
> Gregor Horvath <g.horvath at mx.at> wrote:
>>
>> >>>type(['1'])
>><type 'list'>
>>
>> >>>type(('1'))
>><type 'str'>
>>
>>I wonder why ('1') is no tuple????
>
> There were lots of answers, but I'm not sure I saw the "why" addressed.
>
> 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.

-- 
Antoon Pardon



More information about the Python-list mailing list