[Tutor] Function assignment (was: Re: Function type?)

Alan Gauld alan.gauld@blueyonder.co.uk
Tue Jun 10 19:02:01 2003


> Which leads me to another question: Is it possible to define a
function
> immediately as a variable? Something like:

Yes using lambda, but you are restricted to a single expression.

[ See my tutor topic on Functional Programming for how to get
  round this restriction]

def b(n): return n*n

is the same as:

b = lambda n: n*n

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld