When a variable is accessible or valid only within a part of program, it is referred as local scope of variable.
When a variable is accessible or valid inside the whole program, it is referred as global scope of variable.
To access a global variable within a function we use global statement to declare it. for example–
def sample() global x x=20 print(x) x=10 print(x) sample() print(x) OUTPUT 10 20 20