It is often helpful to examine a character and test whether it is upper- or lowercase, or whether it is a character or a digit. The string module provides several constants that are useful for these purposes.
The string string.lowercase contains all of the letters that the system considers to be lowercase. Similarly, string.uppercase contains all of the uppercase letters. Try the following and see what you get:
>>> print string.lowercase >>> print string.uppercase >>> print string.digits
def isLower(ch): return string.find(string.lowercase, ch) != -1
def isLower(ch): return ch in string.lowercase
def isLower(ch): return 'a' <= ch <= 'z'
As an exercise, discuss which version of isLower you think will be fastest. Can you think of other reasons besides speed to prefer one or the other?
Another constant defined in the string module may surprise you when you print it:
>>> print string.whitespace
\t), and newline
(\n).
There are other useful functions in the string module, but this book isn't intended to be a reference manual. On the other hand, the Python Library Reference is. Along with a wealth of other documentation, it's available from the Python website, www.python.org.