In this tutorial, we are going to learn about the global and local variables in Python with a lot of examples. Types of the variable in Python is given below: GLOBAL LOCAL Global Variable in Python If the variable is defined outside or inside of any function, and its value can be achieved by any function, that means its scope is entire the program is called Global Variable. Example: Creating a ...
Here, name is a local variable for the greet () function and is not accessible outside of it. Any variable present outside any function block is called a global variable. Its value is accessible from inside any function. In the following example, the name variable is initialized before the function definition. Hence, it is a global variable.