Python order of conditions
<p>When I enter this code, the program never throws an error, even if I enter a non-number:</p>

<pre><code>user_input = input("Enter a number.")
if user_input.isdigit() and 0 &lt;= float(user_input) &lt;= 10:
    print("A number between 0 and 10.")
else:
    print("Not a number between 0 and 10.")
</code></pre>

<p>But, if I enter this code, the program throws an error if I enter a non-number:</p>

<pre><code>user_input = input("Enter a number.")
if 0 &lt;= float(user_input) &lt;= 10 and user_input.isdigit():
    print("A number between 0 and 10.")
else:
    print("Not a number between 0 and 10.")
</code></pre>

<p>Does anyone know why? Does it really make a difference in which order I type conditions?</p>

<p>In the first case, the <code>isdigit()</code> method is false, so the next condition is not checked.  In the second case, the <code>float()</code> is attempted and raises and exception:</p>

<pre><code>... float('bob')
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 2, in &lt;module&gt;
ValueError: could not convert string to float: bob
&gt;&gt;&gt; 
</code></pre>

python condition