title: How can I change a global variable from within a function?
body: <p>I'm trying to add or subtract from a defined variable, but how can I overwrite the old value with the new one?</p>
  <pre><code>a = 15
  
  def test():
      a = a + 10
      print(a)
  
  test()
  </code></pre>
  <p>Error message:</p>
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File &quot;test.py&quot;, line 7, in &lt;module&gt;
      test()
    File &quot;test.py&quot;, line 4, in test
      a = a +10
  UnboundLocalError: local variable 'a' referenced before assignment
  </code></pre>