addition - Does python have overloaded parameters? -
this question has answer here:
how integrate multiple values parameters without using tuple or list? python have overloaded parameters?
i'm thinking this:
add(1,2) # 3 add(1,2,3,4) # 10 def add(numbers): return sum(list(numbers)) thanks in advance.
you looking arbitrary argument list.
however, doing more work need , not entirely sure trying (or mean efficient algorithm), sum builtin function needed, need read documentation on expects in arguments.
>>> sum([1,2,3]) 6 >>> sum([1,2,3,4,5,6]) 21 or heck, if want go without list or tuple (actually, arguments list using unnecessary syntactic sugar) can then.
def add(*numbers): return sum(numbers) just think little , can put above function.
Comments
Post a Comment