46 of 151 menu

The fsum method of the math module

The fsum method of the math module returns the sum of all terms of a sequence of numbers. The return type is always fractional.

Syntax

import math math.fsum(sequence of numbers)

Example

Let's find the sum of all the members of the sequence of numbers in the list:

import math lst = [1, 2, 3] print(math.fsum(lst))

Result of code execution:

6.0

Example

Now let's apply the fsum method to a sequence of negative numbers:

import math lst = [-2, -4, -6] print(math.fsum(lst))

Result of code execution:

-12.0

See also

  • function sum,
    which also returns the sum of the numbers
  • method factorial of module math,
    which returns the factorial of a number
  • function min,
    which returns the minimum number
  • function max,
    which returns the maximum number
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline