How to Create Global Scoped Variables in Python


In this example we will show how to create global scoped variables in Python.

Source Code

var1 = 6

def my_func():
    print(var1 + 2)

my_func()

# a variable created outside of a function is global, and can be used by anyone
print(var1)

Output:

8
6
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments