In Python, a variable declared outside of the function or in global scope is known as a global variable. This means that a global variable can be accessed inside or outside of the function.
Here is an example of a global variable:
```
x = “global”
def foo(): print(“x inside :”, x)
foo()
print(“x outside:”, x)
```
Output would be:
```
x inside : global
x outside: global
```
If you want to use same name for different scope, you can create a local variable with the same name. A variable declared inside the function’s body or in the local scope is known as a local variable.
```
x = “global”
def foo():
x = x * 2
print(x)
foo()
```
This will output an error because Python treats x as a local variable and x is not defined in local scope.
If you want to modify global variable from a function, global keyword is used before the variable name.
```
x = “global “
def foo():
global x
x = x * 2
print(x)
foo()
```
Output:
```
global global
```
Python has `nonlocal` statement for nested functions that allows to assign to variables in the nearest enclosing scope that is not global. `nonlocal` keyword works similar to `global`, but it works with the nearest enclosing scope.
```
def outer():
x = “local”
outer()
```
Output:
```
inner: nonlocal
outer: nonlocal
```