Sobes.tech
Junior — Middle

What are the variables declared outside functions called in terms of scope?

sobes.tech AI

Answer from AI

Variables declared outside of functions in Python are called global variables. They are accessible throughout the module scope, meaning anywhere in the file where they are declared, unless they are overridden locally within a function.

Example:

x = 10  # global variable

def func():
    print(x)  # access to the global variable

func()  # will output 10

If you need to modify a global variable inside a function, the global keyword is used.

What are the variables declared outside functions… - sobes.tech