put multiple condition in if statement

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sat Mar 11 01:01:23 EST 2006


On Fri, 10 Mar 2006 21:12:57 -0800, Allerdyce.John wrote:

> Hi,
> 
> How can I put multiple condition in if statement?
> 
> I try this, but I can't get that to work.
> 
> if ( (str != " ") && (str != "") ):


>>> if ( (str != " ") && (str != "") ):
  File "<stdin>", line 1
    if ( (str != " ") && (str != "") ):
                       ^
SyntaxError: invalid syntax

Hmmm... it looks like && is a syntax error in Python. That's probably
because Python isn't C or Java or whatever language you're trying to
program in :-)

Python has operators and, or, not that will do what you are trying to do.

You may want to read these first:

http://docs.python.org/ref/bitwise.html
http://docs.python.org/ref/Booleans.html



-- 
Steven.




More information about the Python-list mailing list