Local Scope
Let’s discuss the local scope in detail.
We'll cover the following
Local scope is the scope we will use the most in Python. When we create a variable in a code block, it will be resolved using the nearest enclosing scope or scopes. The grouping of all these scopes is known as the code blocks environment. In other words, all assignments are done in local scope by default. If we want something different, then you’ll need to set your variable to global or nonlocal, which we will be looking at later on in this chapter.
Testing local scope assignment
For now, we will create a simple example using Python’s interpreter that demonstrates local scope assignment!
Get hands-on with 1200+ tech skills courses.