-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path029scope.py
38 lines (29 loc) · 1016 Bytes
/
029scope.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#py3.7 #https://docs.python.org/3/tutorial/classes.html#scopes-and-namespaces-example
def scopeFunction():
def localScope():
test = 'localScope'
def nonlocalScope():
nonlocal test
test = 'nonlocalFuction'
def globalScope():
global test
test = 'globalFunction'
test = 'scope'
localScope()
print('localScope()', test) #localScope() scope
nonlocalScope()
print('nonlocalScope()', test) #nonlocalScope() nonlocalFuction
globalScope()
print('globalScope()', test) #globalScope() nonlocalFuction #####it changed in global scope
print('text variable after:')
scopeFunction()
print('scopeFunction()', test) #scopeFunction() globalFunction
#def both():
# def GlobalNonlocal():
# global test
# nonlocal test ########SyntaxError: name 'test' is nonlocal and global
# test = 'nonlocalGlobal'
# GlobalNonlocal()
# print('GlobalNonlocal()', test)
#both()
#print('both()', test)