else essentially superfluous
<p>I don't have a background in programming, so this is probably really dumb, but I've never considered this before: it seems that the <code>else</code> statement is essentially superfluous because when the condition is False, Python just moves to the next unindented line .</p>

<p>For example, normally you would write: (if not using <code>elif</code>)</p>

<pre><code>x=2
if x == 1: 
    value = "one"
else:
    if x == 2:
        value = "two"
print value
</code></pre>

<p>But this works too:</p>

<pre><code>x=2
if x == 1: 
    value = "one"
if x == 2:
    value = "two"
print value
</code></pre>

<p>Could someone give an example that shows how and when the <code>else:</code> statement is essential?</p>

<p>Else is never a must but is rather a convenience. Here are some:</p>

<pre><code>if x == 1: 
    value = "one"
else:
    value = "not_one"
</code></pre>

<p>or</p>

<pre><code>if x &lt; 1: 
    value = "less_than_one"
elif x &lt; 2:
    value = "between_one_and_two"
else:
    value = "more_than_two"
</code></pre>

<hr>

<p>They can both be rewritten as:</p>

<pre><code>if x == 1: 
    value = "one"
if x != 1:
    value = "not_one"
</code></pre>

<p>or</p>

<pre><code>if x &lt; 1: 
    value = "less_than_one"
if 1 &lt;= x &lt; 2:
    value = "between_one_and_two"
if 2 &lt;= x:
    value = "more_than_two"
</code></pre>

python if-statement syntax