- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python fsum() function
fsum() finds the sum between a given range or an iterable. It needs the import of the math library. Its widely used in mathematical calculations.
Syntax
Below is the syntax of the function.
maths.fsum( iterable ) The iterable can be a range, array , list. Return Type : It returns a floating point number.
Below are the example on how fsum function on a single number or on group of elements in a list.
Example
import math # Using range print(math.fsum(range(12))) # List of Integers listA = [5, 12, 11] print(math.fsum(listA)) # List of Floating point numbers listB = [9.35, 6.7, 3] print(math.fsum(listB))
Output
Running the above code gives us the following result −
66.0 28.0 19.05
Advertisements