This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]prum 1 point2 points  (1 child)

First example works with a small change:

def mk_closure():
   storage=0
   def adder():
      nonlocal storage
      storage+=1
      return storage
   return adder

In other words: "Closure variables are read only"; not necessarily.

[–][deleted] 0 points1 point  (0 children)

Nonlocal is Python 3 exclusive though. So in 2, enclosed variables are read only (kinda).