<abbr id="ciwa6"><option id="ciwa6"></option></abbr>
  • <sup id="ciwa6"><kbd id="ciwa6"></kbd></sup>
    <small id="ciwa6"></small>
  • 千鋒教育-做有情懷、有良心、有品質的職業教育機構

    400-811-9990
    手機站
    千鋒教育

    千鋒學習站 | 隨時隨地免費學

    千鋒教育

    掃一掃進入千鋒手機站

    領取全套視頻
    千鋒教育

    關注千鋒學習站小程序
    隨時隨地免費學習課程

    上海
    • 北京
    • 鄭州
    • 武漢
    • 成都
    • 西安
    • 沈陽
    • 廣州
    • 南京
    • 深圳
    • 大連
    • 青島
    • 杭州
    • 重慶
    當前位置:成都千鋒IT培訓  >  技術干貨  >  Python math 模塊

    Python math 模塊

    來源:千鋒教育
    發布人:xqq
    時間: 2023-11-09 15:02:28

    先來看一下math模塊中包含內容,如下所示:

    >>>importmath>>>dir(math)['__doc__','__loader__','__name__','__package__','__spec__','acos','acosh','asin','asinh','atan','atan2','atanh','ceil','copysign','cos','cosh','degrees','e','erf','erfc','exp','expm1','fabs','factorial','floor','fmod','frexp','fsum','gamma','gcd','hypot','inf','isclose','isfinite','isinf','isnan','ldexp','lgamma','log','log10','log1p','log2','modf','nan','pi','pow','radians','sin','sinh','sqrt','tan','tanh','tau','trunc']

    接下來具體看一下該模塊的常用函數和常量。

    ceil(x)返回x的上限,即大于或者等于x的最小整數。看下示例:

    importmathx=-1.5print(math.ceil(x))

    floor(x)返回x的向下取整,小于或等于x的最大整數。看下示例:

    importmathx=-1.5print(math.floor(x))

    fabs(x)返回x的絕對值。看下示例:

    importmathx=-1.5print(math.fabs(x))

    fmod(x,y)返回x/y的余數,值為浮點數。看下示例:

    importmathx=3y=2print(math.fmod(x,y))

    factorial(x)返回x的階乘,如果x不是整數或為負數時則將引發ValueError。看下示例:

    importmathx=3print(math.factorial(3))

    pow(x,y)返回x的y次冪。看下示例:

    importmathx=3y=2print(math.pow(x,y))

    fsum(iterable)返回迭代器中所有元素的和。看下示例:

    importmathprint(math.fsum((1,2,3,4,5)))

    gcd(x,y)返回整數x和y的最大公約數。看下示例:

    importmathx=9y=6print(math.gcd(x,y))

    sqrt(x)返回x的平方根。看下示例:

    importmathx=9print(math.sqrt(x))

    trunc(x)返回x的整數部分。看下示例:

    importmathx=1.1415926print(math.trunc(x))

    exp(x)返回e的x次冪。看下示例:

    importmathx=2print(math.exp(2))

    log(x[,base])返回x的對數,底數默認為e。看下示例:

    importmathx=10y=10#不指定底數print(math.log(x))#指定底數print(math.log(x,y))

    常量

    importmath#常量eprint(math.e)#常量πprint(math.pi)

    tan(x)返回x弧度的正切值。看下示例:

    importmathprint(math.tan(math.pi/3))

    atan(x)返回x的反正切值。看下示例:

    importmathprint(math.atan(1))

    sin(x)返回x弧度的正弦值。看下示例:

    importmathprint(math.sin(math.pi/3))

    asin(x)返回x的反正弦值。看下示例:

    importmathprint(math.asin(1))

    cos(x)返回x弧度的余弦值。看下示例:

    importmathprint(math.cos(math.pi/3))

    acos(x)返回x的反余弦值。看下示例:

    importmathprint(math.acos(1))

    以上內容為大家介紹了Pythonmath模塊,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。

    聲明:本站稿件版權均屬千鋒教育所有,未經許可不得擅自轉載。

    猜你喜歡LIKE

    python delattr函數如何使用?

    2023-11-10

    python time.strptime的格式化

    2023-11-10

    pythonGIL在Python多線程的應用

    2023-11-10

    最新文章NEW

    python中pdb模塊怎么用?

    2023-11-10

    Python如何截圖保存?

    2023-11-10

    python?中缺少module怎么辦?

    2023-11-10

    相關推薦HOT

    更多>>

    快速通道 更多>>

    最新開班信息 更多>>

    網友熱搜 更多>>