Have to try

Sheila King usenet at thinkspot.net
Sun Feb 17 00:19:04 EST 2002


On Sat, 16 Feb 2002 21:13:05 -0700 (MST), <kosh at aesaeion.com> wrote in
comp.lang.python in article
<mailman.1013918967.19546.python-list at python.org>:

> On Sat, 16 Feb 2002, Rick Hamilton wrote:
> 
> > So I am trying to do a (what should be) simple thing. I have a string stored
> > in a variable. I want to search that string for the occurrence of a sub
> > string. I have tried
> > Find(s,sub)
> > Rfind
> > MyString.find(sub)
> >
> 
> I think you might find count to be more appropriate if you just want to
> know if it has some string.
> 

Now that is an interesting thought. I had never considered that.

But find will stop at the first occurrence and thus use less resources
(if that is a concern) than count, since count will search the entire
string, and not just stop after the first occurrence.

Just thinking out loud...

-- 
Sheila King
http://www.thinkspot.net/sheila/

"When introducing your puppy to an adult cat,
restrain the puppy, not the cat." -- Gwen Bailey,
_The Perfect Puppy: How to Raise a Well-behaved Dog_




More information about the Python-list mailing list