In article <[EMAIL PROTECTED]>, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: >On 10 Mar 2006 21:12:57 -0800, [EMAIL PROTECTED] declaimed the >following in comp.lang.python: > >> How can I put multiple condition in if statement? >> > Lesson one: Python is NOT C > >> I try this, but I can't get that to work. >> >> if ( (str != " ") && (str != "") ): > > Lesson two: an empty (aka, null) string is "false", and a non-empty >string is "true", so that gives us > > Lesson three: " " is not equal to " " or " " so you >might want to do strip whitespace first... > >>>> "" == " " >False >>>> " " == " " >False >>>> "".strip() == " ".strip() >True >>>> > > So... Your mixed C/Python simplifies to just... > > if str.strip(): # after removing leading/trailing spaces, > # if not empty, do something
str = " " and str = "\t" fail with your substitution - the OP was looking only for strings containing one space or empty strings. Tab characters and multi-spaces would not match. -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list