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