Allow sum to take *args like max/min

I expected sum to work like max and min where they have a 1 argument form that takes an iterable and a 2+ argument form that takes values. I had to write some code like this

sum([function_a(42), function_b(1), function_b(2)])

which would look nicer without the square brackets

sum(function_a(42), function_b(1), function_b(2))

sum takes a start=0 parameter as an optional second argument, if it were to become keyword-only, then a few Python releases later sum could get a *args form.

The start parameter is currently not keyword-only, which means that there’s likely lots of existing software which passes The initial value as the second argument positionally. Changing it to keyword-only would break this software.

If you are going to pass a fixed number of arguments anyway, why not just add the arguments using the plus + operator?

2 Likes

What are advantages of it over

function_a(42) + function_b(1) + function_b(2)
1 Like