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