Python | fsum()函数

fsum() 是Python中的内置函数,用于在某个范围或某个可数之间求和。要使用此函数,我们需要导入数学库。

null

语法:

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
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享