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
相關用法
- Python cmp()用法及代碼示例
- Python map()用法及代碼示例
- Python hex()用法及代碼示例
- Python ord()用法及代碼示例
- Python dir()用法及代碼示例
- Python int()用法及代碼示例
- Python now()用法及代碼示例
- Python sum()用法及代碼示例
- Python oct()用法及代碼示例
- Python tell()用法及代碼示例
- Python id()用法及代碼示例
- Python seek()用法及代碼示例
注:本文由純淨天空篩選整理自kundankumarjha大神的英文原創作品 Python | fsum() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。