def lambda expressions introduce local scope much like nested defwhich automatically sees names in enclosing functionsthe moduleand the built-in scope (via the legb ruleand per )def knights()title 'siraction (lambda xtitle xreturn action act knights(msg act('robin'msg 'sir robintitle in enclosing def scope return function object 'robinpassed to act acta functionnot its result at ca in this exampleprior to release the value for the name title would typically have been passed in as default argument value insteadflip back to the scopes coverage in if you've forgotten why why use lambdagenerally speakinglambda comes in handy as sort of function shorthand that allows you to embed function' definition within the code that uses it they are entirely optional--you can always use def insteadand should if your function requires the power of full statements that the lambda' expression cannot easily provide--but they tend to be simpler coding constructs in scenarios where you just need to embed small bits of executable code inline at the place it is to be used for instancewe'll see later that callback handlers are frequently coded as inline lambda expressions embedded directly in registration call' arguments listinstead of being defined with def elsewhere in file and referenced by name (see the sidebar "why you will carelambda callbackson page for an examplelambda is also commonly used to code jump tableswhich are lists or dictionaries of actions to be performed on demand for examplel [lambda xx * lambda xx * lambda xx * inline function definition list of three callable functions for in lprint( ( )prints print( [ ]( )prints the lambda expression is most useful as shorthand for defwhen you need to stuff small pieces of executable code into places where statements are illegal syntactically the preceding code snippetfor examplebuilds up list of three functions by embedanonymous functionslambda