λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

University of California, Berkeley/ElectricalEngineering & ComputerSciences

LAB_day 6

Nonlocal

def g(x) :

  def f():

    x = 10

    x = x + 2

  f()

  print(x)

g(20)

 

def g(x):

  def f():

    x = x - 8

  f()

  print(x)

g(20)

 

By default,

-   you can access variables in parent frames

-   you cannot modify variables in parent frames

nonlocal statements allow you to modify a name in a parent frame instead of creating a new binding in the current frame

'University of California, Berkeley > ElectricalEngineering & ComputerSciences' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

(Higher-Order) Functions, Sequences, Recursion and TreeRecursion, Trees  (0) 2019.07.18
Iterators & Generators  (0) 2019.07.17
Mutable Functions & Growth  (0) 2019.07.16
Week 4  (0) 2019.07.16
Mutable Sequences  (2) 2019.07.12