Python| fsum()函数
fsum()是Python中的内置函数,用于查找某个范围或可迭代对象之间的总和。要使用此函数,我们需要导入数学库。
句法 :
maths.fsum( iterable )
范围 :
iterable : Here we pass some value
which is iterable like arrays, list.
采用 :
fsum() is used to find the sum
of some range, array , list.
返回类型:
The function return a
floating point number.
演示fsum() 的代码:
# 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))
输出 :
45.0
11.0
7.99