local and Global scope of variables

'''
Scope of a variable is defined as the area with in which the variable is accessible.

variable is a label for a location in the memory.

Not all variables are accessible, and not all variables exist for the same amount of time.

types of variables:

variables can be local and global

local variables are the variables that can be accessed in a local scope .ie with in the respective loop/function/if-else statement etc

global variables are the variables that can be accessed in globally

for example
'''
a= 25
def akansha():
a= 10
print("case 1 " , a)
akansha()

''' in the above case 10 is printed as it takes local value of a
'''

a= 25
def akansha():

print("case 2" ,a)
akansha()

''' in the above case 25 is printed as the program could not find a in local scope '''


'''Global key word helps the programmer to get the permission for python to change the global variable
in the local scope'''


a= 25
def akansha():
global a
a =a*2
print("case 3" ,a)
akansha()

'''
In the above example the value of a is changed using the Global key word
'''


'''Nested functions and their scope .'''



def func1():
a = 25 # this is local scope of functon 1
print("This is function 1" ,a)
def func2():
global a # this is local scope of function 2
a=37
# print("this is function 2", a)
func2()
print("This is function 1 after call of function 2" ,a)

func1()
'''
1.a is a local variable of function 1
2.function 2 is trying to change the global variable a (which is not the same as a of function 1)
3.result of before and after function one stays the same as 25 .
4.since global key word does not changes , value of other local variables.
'''


#OUTPUT
'''

case 1 10
case 2 25
case 3 50
This is function 1 25
This is function 1 after call of function 2 25

you can copy the code to your python interpreter and it will work.
'''