Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.fsum() Method

Python math.fsum() Method

Python math Module Python math Module

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

Python version: 2.6

Syntax

The syntax of 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 computes the sum of all elements:

Example

Import the math package

import

math

Calculating 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 math Module