Easy Tutorial
❮ Python File Readline Python Multithreading ❯

Python math.fsum() Method

Python math Module

The math.fsum(iterable) method in Python calculates the sum of elements in an iterable (tuple, array, list, etc.).

Python Version: 2.6

Syntax

The syntax for the math.fsum() method is as follows:

math.fsum(iterable)

Parameter Description:

Return Value

A floating-point value representing the sum of all elements in the iterable.

Example

The following example calculates the sum of all elements:

Example

# Import the math package
import math

# Calculate the sum of all elements
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]))

Output result:

15.0
1340.0
8.0

Python math Module

❮ Python File Readline Python Multithreading ❯