Python sum()- Funktion
Beispiel
Fügen Sie alle Elemente in einem Tupel hinzu und geben Sie das Ergebnis zurück:
a = (1, 2, 3, 4, 5)
x = sum(a)
Definition und Verwendung
Die sum()
Funktion gibt eine Zahl zurück, die Summe aller Elemente in einer Iterable.
Syntax
sum(iterable,
start)
Parameterwerte
Parameter | Description |
---|---|
iterable | Required. The sequence to sum |
start | Optional. A value that is added to the return value |
Mehr Beispiele
Beispiel
Beginnen Sie mit der Zahl 7 und fügen Sie alle Elemente in einem Tupel zu dieser Zahl hinzu:
a = (1, 2, 3, 4, 5)
x = sum(a, 7)