Python 'OR' syntax

Posted on
Mon Oct 07, 2019 11:00 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Python 'OR' syntax

I have a situation in which all my OR terms won't fit on one line. How do I write the IF expression on multiple lines?
e.g.,

Code: Select all
if A  = 1 or B = 1: # how does one write this on two lines?
      indigo.actionGroup.execute(12345)

Posted on
Mon Oct 07, 2019 11:09 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Python 'OR' syntax

Code: Select all
if ( a==1 or
    b ==2 or
    c ==3 ): indigo.actionGroup.execute(12345)

have a starting ( and and ending )

also with \ at the end of the line indicates the next line is actually part of this line
Code: Select all
if  a==1 or \
    b ==2 or \
    c ==3 : indigo.actionGroup.execute(12345)


I believe that is correct.

I prefer the () .. a little easier to read

Karl

Posted on
Mon Oct 07, 2019 11:35 pm
SMUSEBY offline
Posts: 511
Joined: Sep 16, 2009
Location: California

Re: Python 'OR' syntax

That ( ... ) worked very nicely.
Thank you.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests

cron