Math 模块的使用 | 学习笔记

简介: 快速学习 Math 模块的使用

开发者学堂课程【Python 入门 2020年版:Math 模块的使用】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/639/detail/10355


Math 模块的使用

math 模块保存了数学计算的方法,可以很方便的实现数学运算。

 

math 模块的应用

1.Important math

一些常量是需要知道的,e=2.718281828459045,inf=inf 是代表无限,nan=nan 代表非数,pi=3.141592653589793,tau=6.283185307179586。

还有一些相关的三角函数运算也可以了解一下。

acos(*args, **kwargs): # real signature unknown“”“Return the arc cosine (measured in radians)ofx. Pass

def acosh(*args,**kwargs):#real signature unknown”“”Return the inverse hyperbolic cosine of x.""" pass

def asin(*args,**kwargs):#real signature unknown

“”“Return the arc sine (measured in radians)of x.""" pass

def asinh(*args,**kwargs):#real signature unknown“”“Return the inverse hyperbolic sine of x.""" pass

2.math.factorial

math.factorial () 可以直接写 6,print(math.factorial(6)) 这个就是求阶层的,如果要求阶层其实可以直接掉内置函数,math 模块里用这个方法就可以。

3.math.floor #向下取整

math.floor 结果向下取整。math.floor()floor 是地板的意思。它的作用是这样的,它里边需要一个浮点数,比如说 12.98,这时 math.floor(12.98 )  结果 12,它的结果是向下取整。

4.math.ceil #向上取整。

除了地板以外还有天花板,叫 math.ceil() 举例 math.ceil(15.0001) 来运算一下结果,此时结果为 16,它的作用是向上取整,这么一个情况。

5.math.pow #取幂函数

除了向上和向下之外,还有 math.pow,举例 math.pow(2,10)的结果为1024,它的作用是幂运算,此外负数开平方根,它会报错。

6.math round #内置函数,实现四舍五入到指定位数。

注意,很多同学都容易出错,math 里是没有 round 的。round 四舍五入是一个内置函数,不是 math 里用到的函数。整理一下便是 round 是内置函数,实现四舍五入到指定位数。

7、具体说明三角函数(math.sin,math.cos,math.tan)

(1).举例说明 sin

①.可以知道 Sin30 度等于 0.5

②.填写 print(math.sin(30)),这是弧度,π=180 度。

③.π 是角度,所以应该填写为 print(math.sin(math.pi/6)) 这时运行结果为0.4999994,无限接近于 0.5,为什么不等于 0.5 是因为 π 是一个无限不循环小数。

(2)再举 cos 与 tan 的例子

①.print(math.cos(math.pi/3)),cos30 度 也是等于 0.5 的,它的结果也是无限接近于 0.5.

②.print(math.tan(math.pi/2))时 tan90 度是无限大的,也是不存在的,而此时结果为 1.633123935319537e+16 这个结果也是十分大的。

相关文章
|
6月前
|
Python
python之math,random模块的使用方法
python之math,random模块的使用方法
|
3月前
|
Python
Python学习 -- Math模块和Random模块
Python学习 -- Math模块和Random模块
14 0
|
3月前
python-math.floor()函数
python-math.floor()函数
35 0
|
3月前
python-math.sqrt()函数
python-math.sqrt()函数
25 0
|
4月前
总结一些Math的常规用法,什么是math?
总结一些Math的常规用法,什么是math?
54 1
|
9月前
我这就是给自己看的math模块,想到一点加一点,过一下吧
我这就是给自己看的math模块,想到一点加一点,过一下吧
28 0
|
8月前
|
数据挖掘
math与floor的关系与作用
math与floor的关系与作用
72 0
python——数学模块(math模块)(2)
python——数学模块(math模块)(2)
python——数学模块(math模块)(1)
python——数学模块(math模块)(1)
python——数学模块(math模块)(1)
python——数学模块(math模块)(3)
python——数学模块(math模块)(3)