Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Ref: stackoverflow.com/questions/1261875/python-nonlocal-statement
- from __future__ import print_function #Compatibilidade func print python 2/3
- global x #OPC -> main
- x = 0
- def fext():
- x = 1
- def fin_nl():
- #Var nao local da funcao interna, pega da func externa (fext)
- nonlocal x
- x = 2
- print("fin_nl: ", x)
- def fin_l():
- #Variavel local
- x = 3
- print("fin_l: ", x)
- fin_nl()
- fin_l()
- print("fext: ", x)
- #
- def f_varg():
- #Variavel global
- global x
- x = 4
- print("f_varg: ", x)
- #
- #MAIN
- fext()
- print("main: ", x)
- f_varg()
- print("main: ", x)
- """
- ANTES DE EXECUTAR O CÓDIGO,
- Preencher abaixo os valores que serão impressos
- fin_nl: x
- fin_l: x
- fext: x
- main: x
- f_varg: x
- main: x
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement