'in' operator
Rainer Deyke
root at rainerdeyke.com
Sat Feb 17 02:50:07 EST 2001
"Walter Moreira" <walterm at cmat.edu.uy> wrote in message
news:mailman.982374799.24358.python-list at python.org...
> Why the following test raise an error?
>
> >>> '' in 'yY'
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'in <string>' requires character as left operand
>
> I would expect it to give 0, false.
I would expect it to give 1, since "" is a substring of "yY". Given this
basic misunderstanding of what '"" in "yY"' is supposed to do, raising an
exception seems a reasonable compromise. If you want to check if something
is either "y" or "Y", use 'resp in ("y", "Y")'.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list