'<char> in <string>' works, why doesnt '<string> in <string>'?
justin at iago.org
Sat Mar 9 01:20:15 CET 2002
morton at dennisinter.com (damien morton) writes:
>>>> 'c' in 'the quick brown fox'
>>>> 'fox' in 'the quick brown fox'
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> TypeError: 'in <string>' requires character as left operand
> is this by design?
> is there any reason why '<string> in <string>' shouldnt work?
The "in" operator tests to see if the first operand is an element of
the sequence which is the second element. A string is a sequence of
characters (which are 1-element strings). Thus, the only thing which
can be an element of a string is a single character.
More information about the Python-list