45 of 151 menu

The sum method

The sum method returns the sum of all members of a sequence of numbers. The type of the return value depends on the numbers being added.

Syntax

sum(sequence of numbers)

Example

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

lst = [1, 2, 3] print(sum(lst))

Result of code execution:

6

Example

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

lst = [2.1, 4.2, 4.3] print(sum(lst))

Result of code execution:

12

See also

  • method fsum,
    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