Nested Scopes

Nested scopes and lambda

  • Older versions of python
     def foo():
         a = 0.5
         b = 1.5
         c = 2
         d = 4
         # Call a function with a callback
         plot_function(lambda x,a=a,b=b,c=c,d=d: a*(x**3) + b*(x**2) + c*x + d)
  • Python 2.1:
     def foo():
         a = 0.5
         b = 1.5
         c = 2
         d = 4
     
         plot_function(lambda x: a*(x**3) + b*(x**2) + c*x + d)
<<< O'Reilly OSCON 2001, New Features in Python 2, Slide 20
July 26, 2001, beazley@cs.uchicago.edu
>>>