function with variable arguments

Xah Lee xah at xahlee.org
Fri May 13 05:52:34 EDT 2005


i wanted to define a function where the number of argument matters.
Example:

def Range(n):
    return range(n+1)

def Range(n,m):
    return range(n,m+1)

def Range(n,m,step):
    return range(n,m+1,step)

this obvious doesn't work. The default argument like
Range(n=1,m,step=1) obviously isn't a solution.

can this be done in Python?

or, must the args be changed to a list?

 Xah
 xah at xahlee.orghttp://xahlee.org/




More information about the Python-list mailing list