[Python-Dev] Rationale for sum()'s design? (original) (raw)
Raymond Hettinger python at rcn.com
Tue Mar 15 18:38:03 CET 2005
- Previous message: [Python-Dev] Rationale for sum()'s design?
- Next message: [Python-Dev] Rationale for sum()'s design?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 after all!
+1 This works for me! I use sum() quite a bit and have had no disappointments with the current API.
Raymond
- Previous message: [Python-Dev] Rationale for sum()'s design?
- Next message: [Python-Dev] Rationale for sum()'s design?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]