loading
main.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
39
import unittest

class Scope(unittest.TestCase):
  def test_inner_scope(self):
    self.assertEqual('inner: my inner/local variable', inner())

  def test_enclosed_scope(self):
    self.assertEqual('inner: my enclosed variable', outer())

  def test_global_scope(self):
    self.assertEqual("my global variable", global_scope())



my_var = 'my global variable'

def inner(): 
  my_var = 'my inner/local variable' 
  return ('inner: ' + my_var) 

def outer(): 
	my_var = 'my enclosed variable'
	def inner(): 
		#my_var = 'my inner/local variable' 
		nonlocal my_var
		return ('inner: ' + my_var)
	return inner() 

def global_scope():
  return my_var

print(inner())
print(outer()) 
print(global_scope()) 



if __name__ == '__main__':
  unittest.main()