'IF' Syntax For Alternative Conditions

rshepard at foobar.appl-ecosys.com rshepard at foobar.appl-ecosys.com
Thu Feb 8 09:30:41 EST 2007


On 2007-02-08, Paul Rubin <http> wrote:
> rshepard at nospam.appl-ecosys.com writes:
>> 	if cond1:
>> 	    if cond2:
>> 		do_something.
>
> You can write:
>    if cond1 and cond2:
>       do_something
>
>> 	if cond1 OR if cond2:
>> 	    do_something.
>
> if cond1 or cond2:
>    do_something
>
>>   I've tried using the C syntax for OR (||) but python complained. I'm sure
>> there's a way to do this rather than using if cond1: elif cond2: both with
>> the same code to execute.
>
> Python uses the "and" and "or" keywords for && and ||.

  Allow me to thank all of you who responded with this one article. For
whatever reason, it did not occur to me to use the words 'and' and 'or.'
And, I did not see this in the tutorial or introduction ... which is my
fault.

  So, I do thank all of you.

Rich



More information about the Python-list mailing list