Optional parameters: Difference between revisions

m
Line 522:
See the Python entry in [[Named_Arguments#Python|Named Arguments]] for a more comprehensive description of Python function parameters and call arguments.
 
Note that expression for a default argument of an optional parameter is evaluated only once, when the function definition is definedexecuted, and all calls of the function where that parameter is missing will be initialized to point to that same shared object. So, if the default argument value is a mutable object (e.g. list, dict, etc.), then any changes to it will affect what is seen by future calls of the function:
<pre>
>>> def foo(x, lst=[]):
Anonymous user