Does the Order of Conditions affect Performance?
<p>Does it matter how I order the conditions in Python in respect to the speed of the script? In SQL e.g. it does not as the "Interpreter" assumes which condition ordering would be the fastest. </p>

<p>In Python, as far as I know, the order of conditions will be taken as given by the interpreter. So as an example, if I chain or-conditions, is it better to order the conditions by assumed time they will consume because maybe the interpreter stops even looking for the other conditions when the first one doesn't apply anyway?</p>

<p>Python will not reorder your conditions like in SQL, but it will <a href="https://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow">short circuit</a>. What this means is that it will stop evaluating as soon as possible. So if you have <code>if True == True or long_function_call():</code>, <code>long_function_call()</code> will never be evaluated. This works similarly for <code>and</code> with something like <code>if True == False and long_function_call():</code>. It would be in your best interest to consider this when writing conditional statements and can result in changes in performance.</p>

python performance condition