[ saver([ grows on each callsome see this behavior as feature--because mutable default arguments retain their state between function callsthey can serve some of the same roles as static local function variables in the language in sensethey work much like global variablesbut their names are local to the functions and so will not clash with names elsewhere in program to other observersthoughthis seems like gotchaespecially the first time they run into it there are better ways to retain state between calls in python ( using the nested scope closures we met in this part and the classes we will study in part vimoreovermutable defaults are tricky to remember (and to understand at allthey depend upon the timing of default object construction in the prior examplethere is just one list object for the default value--the one created when the def is executed you don' get new list every time the function is calledso the list grows with each new appendit is not reset to empty on each call if that' not the behavior you wantsimply make copy of the default at the start of the function bodyor move the default value expression into the function body as long as the value resides in code that' actually executed each time the function runsyou'll get new object each time throughdef saver( =none)if is nonex [ append( print(xsaver([ ][ saver([ saver([ no argument passedrun code to make new list each time changes new list object doesn' grow here by the waythe if statement in this example could almost be replaced by the assignment or []which takes advantage of the fact that python' or returns one of its operand objectsif no argument was passedx would default to noneso the or would return the new empty list on the right howeverthis isn' exactly the same if an empty list were passed inthe or expression would cause the function to extend and return newly created listrather than extending and returning the passed-in list like the if version (the expression becomes [or []which evaluates to the new empty list on the rightsee the section "truth testsif you don' recall why real program requirements may call for either behavior function gotchas