global and local variables misconception
<p>I have a question regarding the output from the following code:</p>
<pre><code>def f():

     global s
     print(s)
     s = &quot;That's clear.&quot;
     print(s)

s = &quot;Python is great!&quot;
f()
print(s)
</code></pre>
<p>The output is this:</p>
<blockquote>
<p>Python is great!</p>
<p>That's clear.</p>
<p>That's clear.</p>
</blockquote>
<p>My question is:  Why is it the very last output (i.e. the third output) is also &quot;That's clear&quot; .<br />
How come the third output is not &quot;Python is great!&quot; .
I thought the very last statement from the code (i.e. the print(s)) statement is outside the function f(). So shouldn't print(s) here looks at the s variable that is defined globally? in this case the globally defined variable s would refers to the value &quot;Python is great!&quot;, isn't it?  Sorry there must be some concepts I have mis-understand. I am very newbie to python. Could someone kindly explain this simple concept.</p>