is this a bug?

Berthold Höllmann bhoel at web.de
Sun Jul 7 17:19:13 EDT 2002


"news" <burkhard.kloss at kbcfp.com> writes:

> Python 2.0 (#1, Feb  7 2001, 22:41:16)
> [GCC 2.95.2 19991024 (release)] on sunos5
> Type "copyright", "credits" or "license" for more information.
> >>> "aa" in ["aa", "ab"]
> 1
> >>> "aa" in ["aa"]
> 1
> >>> "aa" in ("aa")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: 'in <string>' requires character as left operand
> 
> Is this a bug, or should this be consistent between lists and tuples?

Yes, it should be consistent between lists and tuples, but no, this is
no bug, because ("aa") is a string and not a tuple:

Python 2.2.1 (#2, May 22 2002, 22:49:15) 
[GCC 3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> ("aa")
'aa'
>>> ("aa",)
('aa',)
>>> 

To make a one telement tuple you have to add the comma.

Greetings

Berthold
-- 
bhoel at web.de / http://starship.python.net/crew/bhoel/
        It is unlawful to use this email address for unsolicited ads
        (USC Title 47 Sec.227). I will assess a US$500 charge for
        reviewing and deleting each unsolicited ad.



More information about the Python-list mailing list