to pass values into lambdas with defaults loop variables may require defaultsnot scopes there is one notable exception to the rule just gave (and reason why 've shown you the otherwise dated default argument technique we just saw)if lambda or def defined within function is nested inside loopand the nested function references an enclosing scope variable that is changed by that loopall functions generated within the loop will have the same value--the value the referenced variable had in the last loop iteration in such casesyou must still use defaults to save the variable' current value instead this may seem fairly obscure casebut it can come up in practice more often than you may thinkespecially in code that generates callback handler functions for number of widgets in gui--for instancehandlers for button-clicks for all the buttons in row if these are created in loopyou may need to be careful to save state with defaultsor all your buttonscallbacks may wind up doing the same thing here' an illustration of this phenomenon reduced to simple codethe following attempts to build up list of functions that each remember the current variable from the enclosing scopedef makeactions()acts [for in range( )acts append(lambda xi *xreturn acts tries to remember each but all remember same last iacts makeactions(acts[ at this doesn' quite workthough--because the enclosing scope variable is looked up when the nested functions are later calledthey all effectively remember the same valuethe value the loop variable had on the last loop iteration that iswhen we pass power argument of in each of the following callswe get back to the power of for each function in the listbecause is the same in all of them-- acts[ ]( acts[ ]( acts[ ]( acts[ ]( all are * =value of last this should be * ( this should be * ( only this should be * ( this is the one case where we still have to explicitly retain enclosing scope values with default argumentsrather than enclosing scope references that isto make this sort of code workwe must pass in the current value of the enclosing scope' variable with scopes