Mega Code Archive

 
Categories / Python Tutorial / 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() count2 = counter(100) print count2() print count()