Created
November 24, 2018 14:47
-
-
Save Fhernd/2db6d836754d2251e4454dcc195b8e3b to your computer and use it in GitHub Desktop.
Acceso a variables de un closure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fn(): | |
n = 0 | |
def fn_closure(): | |
print('n = {}'.format(n)) | |
def obtener_n(): | |
return n | |
def establecer_n(valor): | |
nonlocal n | |
n = valor | |
fn_closure.obtener_n = obtener_n | |
fn_closure.establecer_n = establecer_n | |
return fn_closure | |
f = fn() | |
f() | |
f.establecer_n(10) | |
f() | |
n = f.obtener_n() | |
print(n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment