summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/scope.py
blob: 3aecc0b8d452ddca1346e6f75cf152e61bc031ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# test scoping rules

# explicit global variable
a = 1
def f():
    global a
    global a, a # should be able to redefine as global
    a = 2
f()
print(a)

# explicit nonlocal variable
def f():
    a = 1
    def g():
        nonlocal a
        nonlocal a, a # should be able to redefine as nonlocal
        a = 2
    g()
    return a
print(f())