waltermilner

Untitled

Aug 18th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.22 KB | None | 0 0
  1. #closure with state
  2. def multiplier(f):
  3.     def times(n):
  4.         return n*f  
  5.     return times
  6.  
  7. #stateless function
  8. def times(a,b):
  9.     return a*b
  10.  
  11. mul2 = multiplier(2)
  12. print(mul2(4)) # 8
  13. print(times(2,4)) # 8
Advertisement
Add Comment
Please, Sign In to add comment