[Python-Dev] Rationale for sum()'s design?
python at rcn.com
Tue Mar 15 18:38:03 CET 2005
> OTOH 0 is more compatible and None is a strong candidate too...
None is useless as a default return value for summation. Any code
outside the summation would have to explicitly test for that value.
Stick with zero. Theoretical musings are no reason to make this
function hard to use.
> But I'm not so sure now. Thinking ahead to generic types, I'd like the
> full signature to be:
> def sum(seq: sequence[T], initial: T = 0) -> T.
> and that's exactly what it is today. Conclusion: sum() is perfect
+1 This works for me! I use sum() quite a bit and have had no
disappointments with the current API.
More information about the Python-Dev