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>If the conditions are mutually exclusive then <code>else</code> is superfluous. It's not if the conditions overlap, though.</p>

<pre><code>x = 2
if x &gt; 0:
    print 'foo'
else:                   # better -- elif x &gt; 1:
    if x &gt; 1:
        print 'bar'
</code></pre>

<p>This program prints <code>foo</code>.</p>

<pre><code>x = 2
if x &gt; 0:
    print 'foo'
if x &gt; 1:
    print 'bar'
</code></pre>

<p>This program prints <code>foo</code> <code>bar</code>.</p>

python if-statement syntax