To understand enclosures part of this lecture

I cannot understand the enclosures part of local and global variable lecture.

Hi @sajaldas859_aed297e2c0a64300
Python Variable Scope:
The scope of a variable in python is that part of the code where it is visible. Actually, to refer to it, you don’t need to use any prefixes then.

Example:

b=8
def func():

a=7
print(a)
print(b)              

func()

Output

7
8

Also, the duration for which a variable is alive is called its ‘lifetime’.

In the above code, we define a variable ‘a’ in a function ‘func’. So, ‘a’ is local to ‘func’. Hence, we can read/write it in func, but not outside it.We also declare a variable ‘b’ outside any other python Variable scope, this makes it global scope.Consequently, we can read it anywhere in the program.

Hope this might helps :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.