Scope and nonlocal variables

Hello. I’m playing around with code to understand the concept of scope.

Why does the following not return 101 when I’m calling the function?

def enclosing(x): number = x #Adds 1 to number def add_one(): nonlocal number number + 1 #Call to add 1 to number add_one() return number print(enclosing(100))

number + 1
should be
number += 1
or
number = number + 1

1 Like

Can’t believe I missed that. Thank you for your time.