日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python编程数学函数_【编程】Python数学函数

發布時間:2023/12/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python编程数学函数_【编程】Python数学函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

函數可以做任何事情,主要的使用模式是調用參數并返回值。數學的 math模塊提供了基本的數學函數,可以處理小數運算。使用Python 的Math模塊, 我們可以訪問依據C標準定義的不同的數學函數。這些函數提供了很多算術運算操作,如下取整 floor(x), 上取整 ceil(x), 絕對值fabs(x)等函數。下面依次描述這些函數和用法。

ceil(x)

返回一個不小于x的最小的整數。

print (math.ceil(-125.22))

print (math.ceil(620.12))

print (math.ceil(78.72))

print (math.ceil(math.pi))

輸出

-125

621

79

4

copysign(x, y)

返回帶y的符號的x。在支持符號零的平臺,copysign(1.0, -0.0) 返回 -1.0。 (version 2.6.)

print(math.copysign(12,10))

print(math.copysign(12,-10))

輸出

12.0

-12.0

fabs(x)

返回絕對值。

print(math.fabs(56))

print(math.fabs(-12.8))

print(math.fabs(12.8))

輸出

56.0

12.8

12.8

factorial(x)

返回x的階乘。

print(math.factorial(20))

print(math.factorial(12))

print(math.factorial(17))

print(math.factorial(8))

輸出

2432902008176640000

479001600

355687428096000

40320

floor(x)

返回不大于x的最大的整數。

print (math.floor(18))

print (math.floor(-4.5))

print (math.floor(2.5))

輸出

18

-5

2

fmod(x, y)

返回 x % y.

print(math.fmod(50,10))

print(math.fmod(10,5))

print(math.fmod(-40,24))

print(math.fmod(-15,7))

輸出

0.0

0.0

-16.0

-1.0

frexp(x)

返回尾數和指數對 (m, e)

print(math.frexp(6.8))

print(math.frexp(0))

print(math.frexp(6))

輸出

(0.85, 3)

(0.0, 0)

(0.75, 3)

fsum(iterable)

遞歸求全部所含元素的和。

num = [0.9999999, 1, 2, 3] # Sum values with fsum.

val = math.fsum(num)

print(val)

輸出

6.9999999

isfinite(x)

確定真假。

print(math.isfinite(8))

print(math.isfinite(0.0)) # Python considered 0.0 as finite number print(math.isfinite(0/2))

print(math.isfinite(-100))

輸出

True

True

True

True

isinf(x)

如果x是正或負無限,返回真。

print(math.isinf(8))

print(math.isinf(0.0)) # Python considered 0.0 as finite number print(math.isinf(0/2))

print(math.isinf(-100))

輸出

False

False

False

False

isnan(x)

返回x是否是非數值。

print(math.isnan(10))

print(math.isnan(0.0))

print(math.isnan(0.5))

print(math.isnan(-12))

輸出

False

False

False

False

ldexp(x, i)

返回 x * (2**i),它是 frexp() 反函數。

print (math.ldexp(12,8))

print (math.ldexp(-4.3,4))

print (math.ldexp(2.5,-7))

輸出

3072.0

-68.8

0.01953125

modf(x)

返回x的小數部分和整數部分構成的一個元組。兩個部分和x有相同的符號。整數部分作為小數返回。

print (math.modf(20.22))

print (math.pi)

輸出

(0.21999999999999886, 20.0)

3.141592653589793

trunc(x)

返回x的整數部分。

print(math.trunc(4.454))

輸出

4

exp(x)

自然常數e為底的指數函數:e**x。

print(math.exp(8))

print(math.exp(0.0))

print(math.exp(0.005))

輸出

2980.9579870417283

1.0

1.005012520859401

pow(x, y)

返回x的y次冪。

print(math.pow(10, 2) )

print(math.pow(200, -2))

print(math.pow(2, 2))

輸出

100.0

2.5e-05

4.0

sqrt(x)

返回x的平方根。

print (math.sqrt(0))

print (math.sqrt(10))

print (math.sqrt(2.5))

輸出

0.0

3.1622776601683795

1.5811388300841898

pi

數學常數圓周率,圓的周長和直徑的比值 (3.1415926…)。

print (math.pi)

輸出

3.141592653589793

e

數學常數,自然常數 e (2.71828…)

print (math.e)

輸出

2.718281828459045

Python 基礎

總結

以上是生活随笔為你收集整理的python编程数学函数_【编程】Python数学函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。