How are conditional statements with multiple conditions evaluated?
<p>I'd expect the following two code blocks to be evaluated the same way, but it would seem that is not the case.</p>

<pre><code>if True or False and False:
    print('True')                                                               
else:                                                                           
    print('False')
</code></pre>

<p>True is printed</p>

<pre><code>if (True or False) and False:
    print('True')
else:                                                                           
    print('False')
</code></pre>

<p>False is printed           </p>

<p>Here's my breakdown of the logic:</p>

<p>True or False => True</p>

<p>True and False => False</p>

<p>By substitution, (True or False) and False => True and False => False                                                                                                  </p>

<p>Why does this happen? </p>

<p><code>(True or False)</code> evaluates to <code>True</code>. Therefore <code>(True or False) and False</code> evaluates to <code>True and False</code>, which evaluates to <code>False</code>.</p>

<p>This answer explains the rules for boolean evaluation quite well: <a href="http://stackoverflow.com/a/16069560/1470749">http://stackoverflow.com/a/16069560/1470749</a></p>

python