Matching a constant string at beginning

Hrvoje Niksic hniksic at iskon.hr
Thu Dec 23 09:10:06 EST 1999


"Fred L. Drake, Jr." <fdrake at acm.org> writes:

> 	s = some string...
>         if s.startswith("Simpsons"):
>             do something interesting...

Very cool!

It's long bothered me that you can't check whether a string starts
with a phrase without either consing (s[:3] == 'foo') or resorting to
regexps (re.match('^foo', s)).



More information about the Python-list mailing list