Scope
What's scope?
def myfunc(x, y):
z = x + y
print(z)Local and Global
def hello(name):
reply = 'Hello ' + name # Local variable
name = 'John' # GlobalLast updated
def myfunc(x, y):
z = x + y
print(z)def hello(name):
reply = 'Hello ' + name # Local variable
name = 'John' # GlobalLast updated
def hello(name):
reply = 'Hello ' + name
hello('John')
print(name) # Raises NameError
# But, this does not:
def hello(name):
global reply
reply = 'Hello ' + name
hello('Mike')
print(reply) # Prints 'Mike'