I am studying python from book from Introduction to Computation and Programming Using Python. Here global variables and modules are explained as below
keyword 'global' tells python that name should be defined at the outermost scope of the program rather than within the scope of the function.
I have file name circle.py
pi = 3.14159
def area(radius):
return pi * (radius**2)
Now at python command line I have following
from circle import *
print (pi)
output is 3.14159
print(area(2))
output is 12.56636
Now I defined following
global pi
pi = 2
print(pi)
output is 2
print(area(2))
output is 12.56636
I am expecting output to print 8 as i have changed global variable pi to 2.
Is my understanding is correct?
Please correct me I think I am wrong.
Request to help me in understanding the concepts here.