function later with no argumentsall its defaults are used this was not an issue in the original version of this example because name lived in the global scopeand the code of the lambda will find it there when it is run when nested within functionthoughx may have disappeared after the enclosing function exits passing in enclosing scope values with automatic references while they can make some external dependencies more explicitdefaults are not usually required (since python at leastand are not used for this role in best practice code today ratherlambdas simply defer the call to the actual handler and provide extra handler arguments variables from the enclosing scope used by the lambda are automatically retainedeven after the enclosing function exits the prior code listingfor examplecan today normally be coded as we did earlier-name in the handler will be automatically mapped to in the enclosing scopeand so effectively remember what was when the button was madedef makegui() button(text='ni'command=(lambdahandler( 'spam')) is retained auto no need for defaults we'll see this technique put to more concrete use later when using classes to build your guifor instancethe self argument is local variable in methodsand is thus automatically available in the bodies of lambda functions there is no need to pass it in explicitly with defaultsclass guidef handler(selfab)use selfa and def makegui(self) button(text='ni'command=(lambdaself handler( 'spam'))gui(makegui(mainloop(when using classesthoughinstance attributes can provide extra state for use in callback handlersand so provide an alternative to extra call arguments we'll see how in moment firstthoughwe need to take quick non-gui diversion into dark corner of python' scope rules to understand why default arguments are still sometimes necessary to pass values into nested lambda functionsespecially in guis but you must still sometimes use defaults instead of enclosing scopes although you may still see defaults used to pass in enclosing scope references in some older python codeautomatic enclosing scope references are generally preferred today in factit seems as though the newer nested scope lookup rules in python automate adding user-defined callback handlers