Python Math.fsum() Metoda
Przykład
Zwróć sumę wszystkich przedmiotów:
# Import math Library
import math
# Print the sum of all items
print(math.fsum([1,
2, 3, 4, 5]))
print(math.fsum([100, 400, 340, 500]))
print(math.fsum([1.7,
0.3, 1.5, 4.5]))
Definicja i użycie
Metoda math.fsum()
zwraca sumę wszystkich elementów w dowolnej iteracji (krotki, tablice, listy itp.).
Składnia
math.fsum(iterable)
Wartości parametrów
Parameter | Description |
---|---|
iterable | Required. The list, tuple, array to sum. If the iterable is not numbers, it returns a TypeError |
Szczegóły techniczne
Wartość zwrotu: | Wartość float reprezentująca sumę wszystkich elementów w iterable |
---|---|
Wersja Pythona: | 2,6 |