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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -