I have the code:
def main(m):
res = m
def help(a, b):
print(res)
#res = min(res, a*b)
help(3,2)
return res
main(3)
The code works. However
def main(m):
res = m
def help(a, b):
print(res)
res = min(res, a*b)
help(3,2)
return res
main(3)
it raise UnboundLocalError: local variable 'res' referenced before assignment
def main(m):
global res
res = m
def help(a, b):
print(res)
res = min(res, a*b)
help(3,2)
return res
main(3)
It seems that I add global res does not change. what happens here? How to update res inside the function help?