The Python FSUM function is one of the Python Mathematical Function which is used to calculate and return the sum of iterates (Tuples and Lists). In this article we will show you, How to use FSUM() function in Python Programming language with example.

### Syntax of a Python FSUM Function

The basic syntax of the FSUM Function in Python Programming Language is as shown below:a

1 |
Math.fsum(Iterators); |

**Number:** It can be a number or a valid numerical expression.

- If the
*number*argument is positive or negative number, FSUM() function will calculate and return the sum of iterated (Tuples and Lists). - If the
*number*argument is not a number, FSUM() function will return**TypeError**

## Python FSUM Function Example

The Python FSUM function used to calculate and return the sum of iterates. In this example, We are going to return the same for different data types and display the output

**PYTHON CODE**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Python FSUM Function import math Tup = (10, 20, 12, -40 , 50) # Tuple Declaration Lis = [-98, 32, -39, -42 , 15] # List Declaration print('Calculating SUM of Tuple Item = %.2f' %math.fsum(Tup)) print('Calculating SUM of Tuple Item = %.2f' %math.fsum(Lis)) print('Calculating SUM of Tuple Items Directly = %.2f' %math.fsum((1, 2, 3, 4, 5))) print('Calculating SUM of List Items Directly = %.2f' %math.fsum([10, 20, 30, 40])) print('SUM of Decimal Tuple Items Directly = %.2f' %math.fsum((1.25, 2.45, 3.2, 4, 5.95))) print('SUM of Decimal List Items Directly = %.2f' %math.fsum([2.45, 20.24, 3.95, 4.59])) print('SUM of List of String Items Directly = %.2f' %math.fsum(['a', 'b', 'c', 'd'])) |

**OUTPUT**

**ANALYSIS**

- At the beginning, We declared Python List and Tuple with some random values.
- Within the first two statements, We used the Python Tuple and List items as the arguments for FSUM() Function. If you observe the above screenshot, FSUM() function is working perfectly on them.
- Within the next two statements, We passed the Positive integer Tuples and Lists as the FSUM() Function argument. From the above screenshot you can observe that, FSUM() Function is returning output.
- Within the next two statements, We passed both the Positive and negative decimal Tuples and Lists as the FSUM() Function arguments. As we said before, FSUM() Function is returning the output.
- Last, We tried FSUM() Function on List of String values. As we said before, this will return
**TypeError**as output

Thank You for Visiting Our Blog

## Leave a Reply