In the beginning, I assume that you know how to define your own functions — but not only that, you know how to write functions with multiple parameters and can return multiple values using tuples.


If you do not familiar with defining your own function, the article below will give you more information about it.

We will now discuss the idea of scope in the context of user-defined functions. You have been defining variables in your programs. So far, you have been using these variables without any problems. However, it would be best if you remembered that not all objects you define are always accessible everywhere in a program. This is the idea of scope, which tells you which part of a program an object or a variable may be accessed.

The variables or objects, such as functions that are defined in your program, have a name, as does the function.

There are several types of scope. The first one is the global scope, which means that it is defined in the main body of a script. The second one is the local scope. Local scope means that it is defined within a function. Once the function’s execution is done, any variable inside the local scope terminates, which means you cannot access those variables anymore outside of the function definition.

#technology #software-development #data-science #data analysis

Scope of Variable and LEGB Rule
1.10 GEEK