Simple Closure Example : Nested function : Function PYTHON TUTORIALS


PYTHON TUTORIALS » Function » Nested function »

 

Simple Closure Example


def counter(start_at=0):
     count = [start_at]
     def incr():
         count[0+= 1
         return count[0]
     return incr

count = counter(5)
print count()
print count()
count2 = counter(100)
print count2()
print count()



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Function
» Nested function