First page Back Continue Last page Overview Graphics

Global Variables in Functions

So far, we are capable of reading global variables, but we can't change them.

If you need read and write access,

the variable has to be denoted as global with the keyword “global

def f():

global s

print(s)

s = "dog"

print(s)

s = "cat"

f()

print(s)

output:

cat

dog

dog