[Tutor] membership
Pijus Virketis
virketis@fas.harvard.edu
Tue, 04 Dec 2001 20:05:32 -0500
John,
>t2
>a little red moon
>Traceback (most recent call last):
> File "C:\Python21\Tools\idle\amembership.py", line
>10, in ?
> if ("re" in t2):
>TypeError: 'in <string>' requires character as left
>operand
As the error message states, the thing for which you are asking "in" to
look for in some string must be a character, or equivalently a string of
lenght one. So, you can ask: "is letter 'r' in this string?" but not "is
word 're' in this string?" Of course, Python has ways to look for words in
strings as well. Check out the string module here:
http://www.python.org/doc/current/lib/module-string.html and in particular
look at string.find() and (perhaps) string.count().
Cheers,
-P
------------------------------------------------------------
PGP PUBLIC KEY: www.fas.harvard.edu/~virketis/links
My weblog: www.fas.harvard.edu/~virketis