python order of evaluation with ands in if statements -


it's common put in check none or have similar error catch. need if statement depends on x:

if x == none:    if x[0]>0:      ... # code 

can safely combine if statements (for code brevity)?

if x != none , x[0]>0:      ... # code 

or interpreter not guarantee order of evaluation , stopping after first false?

yes safe, because operators and , or short-circuits.

note:

  • one recommendation use is if want check if object none:

    if x not none , x[0] > 0:     # ... 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -