python math標準庫的使用

math— 數學函數(第三方標準庫)

作用:提供函數完成特殊的數學運算。

調用方法

import math

1.三個常數e,pi和tau

import math 
print(math.pi)
print ( math.e)
print(math.tau)

這兩個常數的輸入必須調用math這個第三方標準庫,直接不能使用。

2.各種函數介紹

這個網址上對大部分math 庫中的函數進行了總結和介紹。如果想了解更多的可以去Python官網上面瞭解,或者用help(math)命令
https://blog.csdn.net/zhangyu4863/article/details/81331432

help(math)

3.常用函數介紹和使用

  • math.ceil(x)
    返回x的上限,返回最小的整數A (A>=x)。如math.ceil(3.14)返回的整數爲4

  • math.fabs(x)
    返回絕對值x。

  • math.factorial(x)
    返回 x!。如果x不是積分或者是負的,就會產生ValueError。

  • math.floor(x)
    返回x的下限,返回一個值最大整數A (A<=x)。如math.floor(3.14)返回的整數爲3

  • math.exp(x)
    返回 ex也就是 math.e**x

  • math . pow(x,y)
    返回x的y次方,即返回 x**y

  • math.sqrt(x)
    返回√x

  • math.degrees(x)
    將角x從弧度轉換成角度。

  • math.radians(x)
    把角x從度轉換成弧度。

  • math.acos(x)
    返回 x 的反餘弦

  • math.asin(x)
    返回 x 的反正弦。

  • math.atan(x)
    返回 x 的反正切。

  • math.cos(x)
    返回 x 的餘弦。

  • math.sin(x)
    返回 x 的正弦。

  • math.tan(x)
    返回 x 的正切。

help(pow())#查看函數的用法

大致內容也就這些了,有興趣的可以去Python官網瞭解一下,我在這裏也只是列舉了簡單的用法。詳細說明也可以看我下面推薦的博客文章

1.[python標準庫]math——數學函數
2.標準庫簡介
3.知乎

發佈了41 篇原創文章 · 獲贊 88 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章