Python中調(diào)用數(shù)學(xué)函數(shù)需要導(dǎo)入math模塊,然后使用該模塊提供的內(nèi)置函數(shù)。
以下是一些常用的數(shù)學(xué)函數(shù)的調(diào)用方法:
import math
result = math.sqrt(16)
print(result) # 輸出:4.0
import math
result = math.fabs(-5)
print(result) # 輸出:5.0
import math
result = math.ceil(3.7)
print(result) # 輸出:4
import math
result = math.floor(3.7)
print(result) # 輸出:3
import math
result = round(3.7)
print(result) # 輸出:4
import math
result = math.pow(2, 3)
print(result) # 輸出:8.0
import math
result = math.log(10)
print(result) # 輸出:2.302585092994046
import math
result = math.exp(1)
print(result) # 輸出:2.718281828459045
import math
result = math.sin(math.pi/2)
print(result) # 輸出:1.0
import math
result = math.cos(math.pi)
print(result) # 輸出:-1.0
這些是常用的數(shù)學(xué)函數(shù)的調(diào)用方法,math模塊還提供了其他數(shù)學(xué)函數(shù),可以通過閱讀Python官方文檔或math模塊的文檔了解更多函數(shù)的用法。