Program - nonlocal keyword comes in handy


Topic: Program - nonlocal keyword comes in handy

Solution

def outer():
    x = 1
    print('outer before:', x)
    def inner():
        nonlocal x
        x = 2
        print("inner:", x)
    inner()
    print("outer after:", x)
outer()



List all Python Programs