Complex compound expressions
Skip Montanaro
skip at pobox.com
Sat Aug 17 15:22:14 EDT 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 pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html
More information about the Python-list
mailing list