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><code>else</code> <em>remembers</em> that the condition was <code>False</code>. For example, consider this code:</p>

<pre><code>if x == 1:
    x = 2
    print("bar")
else:
   if x == 2:
       print("foo")
</code></pre>

<p><em>With</em> the <code>else</code>, only one of "bar" or "foo" will be printed.</p>

<p><em>Without</em> the <code>else</code>, both "bar" and "foo" can be printed since the value of <code>x</code> can change.</p>

<p>This also can help with 'overlapping' conditions:</p>

<pre><code>if x &gt; 10: 
    print("big")
elif x &gt; 5: 
    print("medium")
elif x &gt; 1:
    print("sizable")
else:
    print("small")
</code></pre>

python if-statement syntax