next up previous contents
Next: Functions in the string Up: The string module Previous: The string module   Contents

String Constants

Among the constants defined in the string library, some of the most useful ones are digits, which contains the ten decimal digits, and the three strings uppercase, lowercase and letters which contain the 26 uppercase letters of the alphabet, the 26 lowercase letters of the alphabet, and the union of the uppercase and lowercase letters, respectively. These strings are useful for verifying that all of the characters in a string are of a particular type. For example, if we had a character string called code which was supposed to contain only numbers, we could verify this with a function like the following:
import string
def checknum(code):
    ok = 1
    for i in code:
          if i not in string.digits:
               ok = 0
    return ok



Phil Spector 2003-11-12