共計 357 個字符,預計需要花費 1 分鐘才能閱讀完成。
要導入數學函數庫,可以使用 import
關鍵字。Python 的數學函數庫叫做math
,可以通過以下方式進行導入:
import math
這將導入整個 math
庫,你可以使用其中的數學函數和常量。例如,可以使用 math.sqrt()
函數計算平方根,使用 math.sin()
函數計算正弦值,使用 math.pi
常量表示圓周率等等。
以下是一個簡單的示例,演示如何使用 math
庫中的函數:
import math
x = math.sqrt(25)
print(x) # 輸出:5.0
y = math.sin(math.pi/2)
print(y) # 輸出:1.0
z = math.pi
print(z) # 輸出:3.141592653589793
注意,在使用 math
庫中的函數和常量時,需要在函數或常量名稱前加上 math.
前綴。
丸趣 TV 網 – 提供最優質的資源集合!
正文完