大蟒蛇python教程共享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)不是一个数字

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

到此这篇关于python math模块使用方法介绍的文章就介绍到这了,更多相关python math模块内容请搜索<计算机技术网(www.ctvol.com)!!>以前的文章或继续浏览下面的相关文章希望大家以后多多支持<计算机技术网(www.ctvol.com)!!>!

需要了解更多python教程分享python math模块使用方法介绍,都可以关注python教程分享栏目—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/pythontutorial/1209657.html

(0)
上一篇 2022年8月30日
下一篇 2022年8月30日

精彩推荐