Quick actions

cmd+k|ctrl+k

Navigation

Languages

Scoping - 3

Snippet info

Language

Python

Visibility

public

Author

petersnpan2047

Created

2026-05-04T04:26:50.841788Z

Updated

2026-05-04T04:30:10.84983Z

#x = 1
def a():
    #global x
    #print(x+1)   # global x
    x = 1
    y = 2  
    def b():
        nonlocal y    # y is not global, y is also not local, so must specify here
        y = y + 1
        print(y,x)
    b()
    print(y)
a()
#print(x)
INFO