First page Back Continue Last page Overview Graphics

Global Variables of Functions

Local variables of functions can't be accessed, when the function call has finished.

def f():

s = "cat"

print(s)

f()

print(s)

Output of the script:

cat

Traceback (most recent call last):

File "global_local3.py", line 6, in <module>

print(s)

NameError: name 's' is not defined