Fhernd icon

r712_acceso_variables_closure.py

Fhernd | PRO | 11/24/18 01:47:32 PM UTC | 0 ⭐ | 3788 👁️ | Never ⏰ | []
Python |

370 B

|

None

|

0 👍

/

0 👎

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)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎