Hi i am a beginner who is learning Python, i have stumbled across this example in a book and for some reason when i attempt the same code myself i am not receiving the same output? Please help...
def tester(start):
state = start
def nested(label):
nonlocal state
print(label, state)
state += 1
return nested
>>> F = tester(0)
>>> F('spam')
spam 0
>>> F('ham')
ham 1
>>> F('eggs')
eggs 2
My results are not incrementing + 1 each time i run the function, is there something wrong with the book?