python?math模塊使用方法介紹
math常用方法
1.math.ceil()向上取整
import math print(math.ceil(56.1))
57
2.math.floor()向下取整
import math print(math.floor(56.1))
56
3.math.fabs()取絕對值
import math print(math.fabs(56)) print(math.fabs(-56))
56.0
56.0
4.math.fmod()求模運算
import math print(math.fmod(56,2))
0.0
5.math.isnan()判斷是不是(nan)不是一個數(shù)字
import math print(math.isnan(56)) print(math.isnan(math.nan))
False
True
注意:不是數(shù)字則返回Ture,是數(shù)字則返回Flase
6.math.isinf()判斷是不是無窮大
import math print(math.isinf(56)) print(math.isinf(math.inf))
False
True
注意:正無窮大或負無窮大則返回Ture,否則返回Flase
7.math.isfinite()判斷是不是無限
8.math.e 屬性,自然常數(shù)
返回歐拉數(shù)
9.math.pi 圓周率
返回圓周率
import math print(math.e) print(math.pi)
2.718281828459045
3.141592653589793
10.math.power 冪次方
11.math.sqrt 開平方根
import math print(math.pow(2,2)) print(math.sqrt(4))
4.0
2.0
到此這篇關(guān)于python math模塊使用方法介紹的文章就介紹到這了,更多相關(guān)python math模塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python使用matplotlib.pyplot?as?plt繪圖圖層優(yōu)先級問題
這篇文章主要介紹了Python使用matplotlib.pyplot?as?plt繪圖圖層優(yōu)先級問題.文章圍繞主題展開詳細內(nèi)容需要的小伙伴可以參考一下2022-04-04利用soaplib搭建webservice詳細步驟和實例代碼
這篇文章主要介紹了使用python soaplib搭建webservice詳細步驟和實例代碼,大家可以參考使用2013-11-11Python在for循環(huán)里處理大數(shù)據(jù)的推薦方法實例
這篇文章主要介紹了Python在for循環(huán)里處理大數(shù)據(jù)的推薦方法實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-01-01