functions, optional parameters

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri May 8 13:26:52 EDT 2015


On Sat, 9 May 2015 01:48 am, Ian Kelly wrote:

> On May 8, 2015 9:26 AM, "Steven D'Aprano" <
> steve+comp.lang.python at pearwood.info> wrote:
>>
>> Do you think that Python will re-compile the body of the function every
> time
>> you call it? Setting the default is part of the process of compiling the
>> function.
> 
> To be a bit pedantic, that's not accurate. The default is evaluated when
> the function object is created, i.e. when the def statement is executed at
> runtime, not when the underlying code object is compiled.

Yes, that is the pedantically correct version.

"Technically correct -- the best kind of correct."



-- 
Steven




More information about the Python-list mailing list