title: Python nonlocal statement / keyword
body: <p>What does <code>nonlocal</code> do in Python 3.x?</p>
  <hr />
  <p><sub>To close debugging questions where OP needs <code>nonlocal</code> and doesn't realize it, please use <a href="https://stackoverflow.com/questions/8447947">Is it possible to modify variable in python that is in outer, but not global, scope?</a> instead.</sub></p>
  <p><sub>Although Python 2 is <a href="https://www.python.org/doc/sunset-python-2/" rel="nofollow noreferrer">officially unsupported as of January 1, 2020</a>, if for some reason you are forced to maintain a Python 2.x codebase and need an equivalent to <code>nonlocal</code>, see <a href="https://stackoverflow.com/questions/3190706">nonlocal keyword in Python 2.x</a>.</sub></p>