def F():
print(x)
def G():
x=2
F()
x=1
G()
#printed output is 1 not 2this is because when python runs the function F(), it does not have any local variable named x so it automatically uses the global variable
def F(x):
print(x)
def G():
x=2
F(x)
x=1
G()this prints 2 because now x is a local variable for F()
Unless we define a variable beforehand, we cant directly use it inside our code. for instance
def G():
x+=2gives an error. we can only do this by using the global keyword