What is a function parameter =[] for?

Ian Kelly ian.g.kelly at gmail.com
Wed Nov 18 19:02:39 EST 2015


On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Thu, Nov 19, 2015 at 10:14 AM, BartC <bc at freeuk.com> wrote:
>> So, looking at some source code, a default value for certain types is only
>> certain to be that value for the very first call of that function?
>
> On the contrary, it is certain always to be that exact object.

"Certain" may be a bit overly strong.

>>> def f(x=42):
...   return x
...
>>> f()
42
>>> f.__defaults__ = (43,)
>>> f()
43



More information about the Python-list mailing list