updated contents from Atlas repo

This commit is contained in:
Luciano Ramalho
2014-10-14 14:26:55 -03:00
parent 40688c038d
commit 981d5bc473
157 changed files with 71134 additions and 1 deletions

63
decorators/local_demo.py Normal file
View File

@@ -0,0 +1,63 @@
"""
>>> f1(3)
>>> b = 8
>>> f1(3)
a = 3
b = 8
>>> f2(3)
Traceback (most recent call last):
...
UnboundLocalError: local variable 'b' referenced before assignment
>>> f3(3)
a = 3
b = 7
b = 6
>>> b = -5
>>> ff = f4()
>>> ff(3)
a = 3
b = 11
b = 6
>>> print('b =', b)
b = -5
"""
def f1(a):
print('a =', a)
print('b =', b)
def f2(a):
print('a =', a)
print('b =', b)
b = a * 10
print('b =', b)
def f3(a):
global b
print('a =', a)
print('b =', b)
b = a * 10
print('b =', b)
def f3b(a):
nonlocal b
print('a =', a)
print('b =', b)
b = a * 10
print('b =', b)
def f4():
b = 11
def f5(a):
nonlocal b
print('a =', a)
print('b =', b)
b = a * 2
print('b =', b)
return f5
import doctest
doctest.testmod(optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)