String functions: what's the difference?

gry at gry at
Thu Mar 9 15:57:08 CET 2006

First, don't appologize for asking questions.  You read, you thought,
and you tested.  That's more than many people on this list do.  Bravo!

One suggestion: when asking questions here it's a good idea to always
briefly mention which version of python and what platform (linux,
windows, etc) you're using.  It helps us answer your questions more

For testing performance the "timeit" module is great.  Try something
  python -mtimeit -s 'import string;from myfile import isLower'

You didn't mention the test data, i.e. the character you're feeding to
It might make a difference if the character is near the beginning or
end of the range.

As to reasons to prefer one or another implementation, one *very*
important question is "which one is clearer?".  It may sound like a
minor thing, but when I'm accosted first thing in the
morning(pre-coffee) about a nasty urgent bug and sit down to pore over
code and face "string.find(string.lowercase, ch) != -1", I'm not happy.

Have fun with python!
-- George Young

More information about the Python-list mailing list