Skip to content

Commit 49eb7e5

Browse files
committed
Add scope and namespace
1 parent 259cc59 commit 49eb7e5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

class/scope_and_namespace/main.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
def testing_scope():
2+
def local_var():
3+
foo = 'local'
4+
print(id(foo))
5+
6+
def nonlocal_var():
7+
nonlocal foo
8+
foo = 'nonlocal'
9+
print(id(foo))
10+
11+
def global_var():
12+
global foo
13+
foo = 'global'
14+
print(id(foo))
15+
16+
foo = 'testing'
17+
print(id(foo))
18+
local_var()
19+
print('local ---->', foo, id(foo))
20+
nonlocal_var()
21+
print('nonlocal ---->', foo, id(foo))
22+
global_var()
23+
print('global ---->', foo, id(foo))
24+
25+
testing_scope()
26+
print('in global ---->', foo, id(foo))

0 commit comments

Comments
 (0)