(xpass along instead of nesting forward reference ok def ( )print(xflat is still often better than nestedf ( if you avoid nesting this wayyou can almost forget about the nested scopes concept in python on the other handthe nested functions of closure (factoryfunctions are fairly common in modern python codeas are lambda functions--which almost naturally appear nested in defs and often rely on the nested scopes layeras the next section explains nested scopesdefaultsand lambdas although they see increasing use in defs these daysyou may be more likely to care about nested function scopes when you start coding or reading lambda expressions we've met lambda briefly and won' cover it in depth until but in shortit' an expression that generates new function to be called latermuch like def statement because it' an expressionthoughit can be used in places that def cannotsuch as within list and dictionary literals like defa lambda expression also introduces new local scope for the function it creates thanks to the enclosing scopes lookup layerlambdas can see all the variables that live in the functions in which they are coded thusthe following code-- variation on the factory we saw earlier--worksbut only because the nested scope rules are applieddef func() action (lambda nx *nreturn action func(print( ( ) remembered from enclosing def prints * prior to the introduction of nested function scopesprogrammers used defaults to pass values from an enclosing scope into lambdasjust as for defs for instancethe following works on all pythonsdef func() action (lambda nx=xx *nreturn action pass in manually because lambdas are expressionsthey naturally (and even normallynest inside enclosing defs hencethey were perhaps the biggest initial beneficiaries of the addition scopes and nested functions