python基础第十五章------------数学模块:math

数学模块:math

这个模块学习时要对比前面的内建函数

导入包:import  math

返回整型的函数  (ceil,floor对比内建函数中的round):

ceil():向上取整(只要有小数点,就往上近1)  

import math
res=math.ceil(6.5)
print(res)

floor():向下取整(小数点后面的数字会删除)

import math
res=math.floor(6.999)
print(res)

返回浮点型的函数:

pow():计算一个数的N次方

print(math.pow(2,3))

sqrt(必须放正数):开平方

print(math.sqrt(9))

modf():将正数和小数分开组成一个元组

返回值:(小数部分,整数部分)

import math
res=math.modf(6)
print(res)
会输出:(0.0,6.0)

copysign():第一个数的正负号由后面一个数的正负号所决定的

import math
res=math.copysign(3,-4)
print(res)
会输出:-3.0

fsum():将容器中的数据进行求和运算(容器不能是str)

import math
str1=[1,2,3,4,5]
res=math.fsum(str1)
print(res)
常数(不是函数):pi   e
圆周率pi
import math
print(math.pi)

import math
print(math.e)
 
 

 



 

 

猜你喜欢

转载自www.cnblogs.com/szc-boke/p/11263282.html