日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python?math模塊使用方法介紹_python

作者:魏大橙 ? 更新時間: 2022-10-16 編程語言

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)不是一個數字

import math
print(math.isnan(56))
print(math.isnan(math.nan))

False
True

注意:不是數字則返回Ture,是數字則返回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 屬性,自然常數

返回歐拉數

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

原文鏈接:https://blog.csdn.net/Thewei666/article/details/125815275

欄目分類
最近更新