0

When Python is processing an or statement, does it calculate all statements, and then check if they are true, or does it process it in a particular order, e.g. from left to right.

For example:

if condition1 == True or process_intensive_calculation(variables) == True:
    run_commands()

Will Python stop if the first condition is True (i.e and only run the second if it is not True), or calculate both terms before determining whether the condition is met.

kyrenia
  • 5,431
  • 9
  • 63
  • 93
  • See also: http://stackoverflow.com/questions/2580136/does-python-support-short-circuiting – Blorgbeard Jul 27 '15 at 01:54
  • Note that usual python style (and preferred style in many other languages) is to prefer `if condition1:` over `if condition1 == True:`. – lvc Jul 27 '15 at 01:57
  • To quickly answer the question (in case someone is too lazy to click on the dupe): if the first statement is [truthy](https://developer.mozilla.org/en-US/docs/Glossary/Truthy), evaluation stops, as the whole thing is now `True`. – MattDMo Jul 27 '15 at 02:10

0 Answers0