When do default parameters get their values set?

Terry Reedy tjreedy at udel.edu
Mon Dec 8 20:37:58 EST 2014


 >>> def f(a="default "+"arg value"): return a

 >>> f.__defaults__
('default arg value',)

Before any calls, the expression has be evaluated.  When f() is called 
with no arg, the local name 'a' is associated with
'default arg value'. Then code execution begins. Use dir(f), for 
instance, to invesigate internals.

-- 
Terry Jan Reedy




More information about the Python-list mailing list