{"id":24140,"date":"2021-10-14T09:09:58","date_gmt":"2021-10-14T03:39:58","guid":{"rendered":"https:\/\/python-programs.com\/?p=24140"},"modified":"2021-11-05T20:53:50","modified_gmt":"2021-11-05T15:23:50","slug":"python-program-for-fsum-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-fsum-function\/","title":{"rendered":"Python Program for fsum() Function"},"content":{"rendered":"

In the previous article, we have discussed Python Program for frexp() Function<\/a>
\nfsum() Function in Python:<\/strong><\/p>\n

The math.fsum() method returns the sum of all iterable items (tuples, arrays, lists, etc.).<\/p>\n

Syntax:<\/strong><\/p>\n

math.fsum(iterable)<\/pre>\n

Parameters:<\/strong><\/p>\n

iterable: This is required. It may be a tuple, list, arrays, etc to sum. If the iterable does not contain numbers, it throws a TypeError.<\/p>\n

Return Value:<\/strong><\/p>\n

It returns a float value representing the sum of the iterable’s items.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [1, 3, 5, 8]\r\nGiven Tuple = (10, 20, 50, 60)<\/pre>\n

Output:<\/strong><\/p>\n

The sum of all list items after applying fsum() function =  17.0\r\nThe sum of all tuple items after applying fsum() function =  140.0<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [15, 20, 40, 10, 30]\r\nGiven Tuple = (45, 30, 10, 5, 6)<\/pre>\n

Output:<\/strong><\/p>\n

The sum of all list items after applying fsum() function =  115.0\r\nThe sum of all tuple items after applying fsum() function =  96.0<\/pre>\n

Program for fsum() Function in Python<\/h2>\n