On Wednesday, December 10, 2014 4:38:18 AM UTC+5:30, rand...@fastmail.us wrote:
> On Tue, Dec 9, 2014, at 16:18, Duncan Booth wrote:
> > The default parameters are actually evaluated when the 'def' statement is 
> > executed and the function object is created from the default arguments
> > and 
> > the previously compiled code block.
> 
> Which means that if you execute the def statement [or lambda] more than
> once, you will get more than one instance of the default parameter.
> 
> >>> def f(): return (lambda x={}: x)
> ...
> >>> f()() is f()()
> False
> >>> g = f()
> >>> g() is g()
> True

Nice example -- thanks.
Elaborates the why of this gotcha -- a def(inition) is imperative.
>From a semantic pov very clean.
>From an expectation pov always surprising.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to