Course Recommendation:

Python global keyword

Example

Declare a global variable inside the function and use it outside the function:
# Create function:
  def myfunction():
  global x
x = "hello"
# Execute function:
myfunction()
# x is now a global variable and can be accessed globally.

print(x)

Running Instance

Definition and Usage