'<char> in <string>' works, why doesnt '<string> in <string>'?
Erik Max Francis
max at alcyone.com
Sat Mar 9 01:14:54 CET 2002
damien morton wrote:
> is this by design?
> is there any reason why '<string> in <string>' shouldnt work?
Yes, it's by design. The in operator deals with membership, rather than
finding subsequences. Strings are a degenerate case, since they're
sequences of "characters" only. For example,
[1, 2] in [1, 2, 3, 4]
would rightly return false, since [1, 2] is not a member of [1, 2, 3, 4]
(that would be something like [[1, 2], 1, 2, 3, 4]). Having in deal
with membership _or_ subsequences would lead to ambiguity, and having it
deal with subsequences among strings alone would be a peculiar
Say what you mean; there's a .find method (or just string.find) for
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ Laws are silent in time of war.
Esperanto reference / http://www.alcyone.com/max/lang/esperanto/
An Esperanto reference for English speakers.
More information about the Python-list