functions and functional programming the lambda operator anonymous functions in the form of an expression can be created using the lambda statementlambda args expression args is comma-separated list of argumentsand expression is an expression involving those arguments here' an examplea lambda , + ( , gets the code defined with lambda must be valid expression multiple statements and other non-expression statementssuch as for and whilecannot appear in lambda statement lambda expressions follow the same scoping rules as functions the primary use of lambda is in specifying short callback functions for exampleif you wanted to sort list of names with case-insensitivityyou might write thisnames sort(key=lambda nn lower()recursion recursive functions are easily defined for exampledef factorial( )if < return elsereturn factorial( howeverbe aware that there is limit on the depth of recursive function calls the function sys getrecursionlimit(returns the current maximum recursion depthand the function sys setrecursionlimit(can be used to change the value the default value is although it is possible to increase the valueprograms are still limited by the stack size limits enforced by the host operating system when the recursion depth is exceededa runtimeerror exception is raised python does not perform tailrecursion optimization that you often find in functional languages such as scheme recursion does not work as you might expect in generator functions and coroutines for examplethis code prints all items in nested collection of listsdef flatten(lists)for in listsif isinstance( ,list)flatten(selseprint(sitems [[ , , ],[ , ,[ , ]],[ , , ]flatten(itemsprints howeverif you change the print operation to yieldit no longer works this is because the recursive call to flatten(merely creates new generator object without actually iterating over it here' recursive generator version that worksf lib fl ff