title: Why I can't use += to change a local variable of a function in the sub-function in it?
body: <h1>Enviroment:</h1>
  <p>Python 3.10.3, VSCode, Windows 11</p>
  <h1>Describing:</h1>
  <p>I write a program with tkinter by Python.</p>
  <pre class="lang-py prettyprint-override"><code>def examination():
      exam = Frame()
      exam.pack()
      quesinfo = []
      quesnumb = 0
  
      def next():
          is_right.forget()
          nextques.forget()
          okayques.grid(column=5, row=2, columnspan=2)
          quesnumb += 1
          quesinfo.append(core())
          question.set(quesinfo[quesnumb][0])
  </code></pre>
  <p>This is just a part of my code, but the problem is here. When I run the program, the interpreter says:</p>
  <pre><code>Exception in Tkinter callback
  Traceback (most recent call last):
    File &quot;C:\Users\${MyName}\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py&quot;, line 1921, in __call__
      return self.func(*args)
    File &quot;d:\Python\Usable Programs\Auto Maths Questions UI\Main.py&quot;, line 102, in next
      quesnumb = quesnumb + 1
  UnboundLocalError: local variable 'quesnumb' referenced before assignment
  </code></pre>
  <p>You know, <code>quesnumb</code> is a local variable, so I can't use <code>global</code> to declare it.
  But, that's joking! Look at to the source code again:</p>
  <pre class="lang-py prettyprint-override"><code>quesinfo.append(core())
  question.set(quesinfo[quesnumb][0])
  </code></pre>
  <p>It's correct, But why <code>quesnumb += 1</code> is not?</p>
  <h1>Fixing and Debugging</h1>
  <p>I tried my best to fix it.<br />
  For testing and dubugging, I replaced <code>quesnumb += 1</code> to <code>quesnumb = 1</code>. It ran successfully!<br />
  I think, maybe <code>quesnumb</code> can just reference or assignment? So I replaced it to <code>quesnumb = quesnumb + 1</code>.</p>
  <pre><code>Exception in Tkinter callback
  Traceback (most recent call last):
    File &quot;C:\Users\${MyName}\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py&quot;, line 1921, in __call__
      return self.func(*args)
    File &quot;d:\Python\Usable Programs\Auto Maths Questions UI\Main.py&quot;, line 102, in next
      quesnumb = quesnumb + 1
  UnboundLocalError: local variable 'quesnumb' referenced before assignment
  </code></pre>
  <p>Uh-huh...
  That's a real Unexpect Wrong...</p>
  <p>I must get the answer in time, because I'll use this program on a competition at Sunday (Mar. 27). Winning the competition is all depends on this program. Could you help me to check the problem and find the root cause? Thanks so much!</p>