"str.contains(part)" or alternatives?
Joseph A. Knapka
jknapka at earthlink.net
Wed Sep 11 23:38:21 EDT 2002
"Delaney, Timothy" wrote:
>
> > From: Stefan Schwarzer [mailto:sschwarzer at sschwarzer.net]
> >
> > "if part in s" disturbs the pattern "if item in sequence"
> > somewhat but that has
> > already been weakened by "if key in dict" (that I like, nonetheless).
>
> In fact, this was the deciding factor in Guido changing his position on 'if
> s1 in s2'. A string has sequence-like behaviour (e.g. it is iterable,
> individual characters can be indexed), but also has its own behaviour (e.g.
> substring containment, all elements are single-character strings).
So in 2.3, can I do this and get the expected result?
>>> "" in "abc"
1
>>> for subst in "abc":
... print subst
...
<empty string>
a
ab
abc
b
bc
c
>>>
Just curious,
-- Joe
"I'd rather chew my leg off than maintain Java code, which
sucks, 'cause I have a lot of Java code to maintain and
the leg surgery is starting to get expensive." - Me
More information about the Python-list
mailing list