How to Use Global and Nonlocal Variables in Python
Introduction
In this article we’ll be taking a look at Global and Non-Local Variables in Python and how you to use them to avoid issues when writing code.
We’ll be starting off with a brief primer on variable scopes before we launch into the how and why of using global and non-local variables in your own functions.
Scopes in Python
Before we can get started, we first have to touch on scopes. For those of you who are less familiar, “scope” refers to the context in which a variable is defined and how it can be accessed or altered or more specifically – from where it can be accessed.
And in programming, like in life, context is important.
By referencing Python right now, you can infer from context that I am referring to the programming language. In another context however, Python could be a