Core Concept Mastery • Python Visual Series Module
Variables created inside a function belong to the local scope of that function, and can only be used inside that function. Variables created outside of a function belong to the global scope, and can be used by anyone, both inside and outside of functions.
msg = "Hello"
def greet():
name = "Alice"
print(msg, name)
greet()
print(name) # Error!
msg = "Hello" is created outside any function, making it a Global variable. It lives in the Global Scope and is accessible from anywhere in the program.