Complex compound expressions

Skip Montanaro skip at
Sat Aug 17 21:22:14 CEST 2002

    Derek> Just a quick question. I am still a little shaky on using
    Derek> parentheses to form complex compound expressions. For example:

    Derek> if character in string.letters or string.digits:
    Derek>             print 'im a character'

The above predicate says "if character is a letter or if string.digits is
not False".  Since string.digits is never the empty string it is never
False.  Try this instead:

    if character in string.letters+string.digits:
        print 'im a character'

I don't see an obvious way for parens to help you without assistance from
some other operator.

Skip Montanaro
skip at

More information about the Python-list mailing list