The Wayback Machine - https://web.archive.org/web/20240204212512/https://www.geeksforgeeks.org/python-fsum-function/
Open In App
Related Articles

Python | fsum() function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

fsum() is inbuilt function in Python, used to find sum between some range or an iterable. To use this function we need to import the math library. Syntax :

maths.fsum( iterable )

Parameter :

iterable : Here we pass some value
which is iterable like arrays, list.

Use :

fsum() is used to find the sum
of some range, array , list.

Return Type :

The function return a
floating point number.

Time Complexity: O(n) where n is the size of the list.

Auxiliary Space: O(1)

  Code demonstrating fsum()

Python3




# Python code to demonstrate use 
# of math.fsum() function
 
# fsum() is found in math library
import math
 
# range(10)
print(math.fsum(range(10)))
 
# Integer list
arr = [1, 4, 6]
print(math.fsum(arr))
 
# Floating point list
arr = [2.5, 2.4, 3.09]
print(math.fsum(arr))


Output :

45.0
11.0
7.99

Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


Last Updated : 16 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials