0
def func (*args)
How to make a code that combains all elements in args
4 RĂ©ponses
+ 2
If you have a function definition:
def func (*args):
...
all elements passed to the function are contained within a list variable called args. So simply
def func(*args):
return sum(args)
print(func(2,3,5,7)) # 17
...can be done. But I have to ask; if all elements come from an input, why not just put the inputs straight into a list and find the sum?
+ 1
I think you'll find a good explanation here https://stackoverflow.com/questions/3394835/use-of-args-and-kwargs
0
What do you mean by "combines all elements"?
0
Simply a function returns a+b+c +....... I don't know how many arguments in func cause they will be an input so the user will input random some values how to make a code that combains all of them