<p>I am trying to figure out this:</p>

<pre><code>c = 1
def f(n):
    print c + n 
def g(n):
    c = c + n

f(1) # =&gt; 2
g(1) # =&gt; UnboundLocalError: local variable 'c' referenced before assignment
</code></pre>

<p>Thanks!</p>

Within a function, variables that are assigned to are treated as local variables by default. To assign to global variables, use the
```
global
```
statement:
```
```
def g(n):
    global c
    c = c + n
```
```
This is one of the quirky areas of Python that has never really sat well with me.