3 ms·
Python Oddness
- makecheck 18y agoThere is another reason to avoid the defaulting trap that is the subject of the article: you don't want something evaluated if it will never be used. Python always evaluates the default values of arguments; this is done at parsing time. So if you define a function f(a=x()) and never call f(), there will still be a call to x(). The first work-around mentioned in the article (to assign None as a value, and test for None before setting a default), is the approach that I prefer when the default value is non-trivial.