[Tutor] Problem with default arguments for function
Alan Gauld
alan.gauld at btinternet.com
Mon Nov 12 01:22:18 CET 2007
"Dick Moores" <rdm at rcblue.com> wrote
> And if the function is rewritten as def fact(n, full=False,
> precision=15)
> there would be the analogous problem involving full.
>
> Is there a way to solve this problem of the unnecessary setting of
> the 2nd argument?
The most common solution I've seen is to write wrappers
around the basic function like:
def fullFact(n, precision=15):
return fact(n,True,precision)
def precisionFact(n, full=False):
return fact(n, full, 15)
Not terribly elegant but is at least short and simple.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list