新聞中心
Python的math庫是一個非常強(qiáng)大的數(shù)學(xué)庫,它提供了大量的數(shù)學(xué)函數(shù)和常量,可以滿足大部分?jǐn)?shù)學(xué)計算的需求,以下是一些常用的math庫函數(shù):

我們提供的服務(wù)有:成都做網(wǎng)站、網(wǎng)站設(shè)計、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、湖濱ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的湖濱網(wǎng)站制作公司
1、math.fabs(x):返回x的絕對值。
2、math.factorial(x):返回x的階乘。
3、math.sqrt(x):返回x的平方根。
4、math.pow(x, y):返回x的y次冪。
5、math.log(x[, base]):返回x的自然對數(shù),base參數(shù)可選,默認(rèn)為e。
6、math.log10(x):返回x的以10為底的對數(shù)。
7、math.ceil(x):返回大于或等于x的最小整數(shù)。
8、math.floor(x):返回小于或等于x的最大整數(shù)。
9、math.modf(x):返回x的整數(shù)部分和x的小數(shù)部分。
10、math.pi:返回圓周率π的值。
11、math.sin(x):返回x的正弦值。
12、math.cos(x):返回x的余弦值。
13、math.tan(x):返回x的正切值。
14、math.asin(x):返回x的反正弦值。
15、math.acos(x):返回x的反余弦值。
16、math.atan(x):返回x的反正切值。
17、math.exp(x):返回e的x次方。
18、math.frexp(x):返回x的尾數(shù)和指數(shù)。
19、math.ldexp(x, exp):返回x乘以2的exp次方。
以下是一些示例代碼:
import math 計算絕對值 print(math.fabs(10)) # 輸出:10.0 計算階乘 print(math.factorial(5)) # 輸出:120 計算平方根 print(math.sqrt(9)) # 輸出:3.0 計算冪 print(math.pow(2, 3)) # 輸出:8.0 計算自然對數(shù) print(math.log(10)) # 輸出:2.302585092994046 計算以10為底的對數(shù) print(math.log10(100)) # 輸出:2.0 計算大于或等于x的最小整數(shù) print(math.ceil(3.6)) # 輸出:4.0 計算小于或等于x的最大整數(shù) print(math.floor(3.6)) # 輸出:3.0 獲取圓周率π的值 print(math.pi) # 輸出:3.141592653589793 計算正弦值 print(math.sin(math.pi / 2)) # 輸出:1.0 計算余弦值 print(math.cos(math.pi)) # 輸出:1.0 計算正切值 print(math.tan(math.pi / 4)) # 輸出:0.9999999999999999
以上就是Python math庫的一些常用函數(shù),希望對你有所幫助。
網(wǎng)頁標(biāo)題:pythonmath庫常用函數(shù)
網(wǎng)站URL:http://fisionsoft.com.cn/article/djchiid.html


咨詢
建站咨詢
