What do you understand by local and global scope of variables ? How can you access a global variable inside the function, if function has a variable with same name?

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
error: Content is protected !!