rememberthoughthat this means the assignment also changes the global xnot local within functionyou can' use both local and global versions of the same simple name if you really meant to print the global and then set local of the same nameyou' need to import the enclosing module and use module attribute notation to get to the global versionx def selector()import __main__ print(__main__ xx print(ximport enclosing module qualify to get to global version of name unqualified classified as local prints local version of name selector( qualification (the partfetches value from namespace object the interactive namespace is module called __main__so __main__ reaches the global version of if that isn' clearcheck out in recent versions python has improved on this story somewhat by issuing for this case the more specific "unbound localerror message shown in the example listing (it used to simply raise generic name error)this gotcha is still present in generalthough defaults and mutable objects as noted briefly in and mutable values for default arguments can retain state between callsthough this is often unexpected in generaldefault argument values are evaluated and saved once when def statement is runnot each time the resulting function is later called internallypython saves one object per default argument attached to the function itself that' usually what you want--because defaults are evaluated at def timeit lets you save values from the enclosing scopeif needed (functions defined within loops by factories may even depend on this behavior--see aheadbut because default retains an object between callsyou have to be careful about changing mutable defaults for instancethe following function uses an empty list as default valueand then changes it in place each time the function is calleddef saver( =[]) append( print(xsaves away list object changes same object each timesaver([ ][ saver([ default not used the benchmarking interlude default used