Variables that are created outside of a function are known as global variables in Python. A global variable can be accessed from the whole program.
Example of how to defines a global variable in Python
Simple example code of creates a global variable and uses it. They can be used inside of functions and outside.
Just declare the variable outside the function or in a global scope.
gv = "Python - Global Variables" def my_func(): print(gv) my_func()
Do comment if you have any doubts and suggestions on this Python variable topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.