Python math库

import math #导包

方法

math.e    		#自然常数e=2.718281828459045
math.pi   		# 圆周率pi  3.141592653589793
math.exp(x)  	#返回e的x次方
math.log(x[, base]) 	# 返回x的以base为底的对数,base默认为e
math.log10(x) 		#返回x的以10为底的对数
math.pow(x, y) 	# 返回x的y次方相当于x**y
math.sqrt(x)   	#x的平方根
math.ceil(x)  		#x向上取整
math.floor(x)    	#x向下取整
math.modf(x)     	#返回x的小数和整数
math.fmod(x, y)  	#返回x%y(取余)
math.factorial(x)  #返回x的阶乘
math.sin(x), math.cos(x), math.tan(x)  	#正弦,余弦,正切
math.asin(x),math.acos(x), math.atan(x) 	#反正弦,反余弦,反正切

测试

print(math.e)	2.718281828459045
print(math.pi)	3.141592653589793
print(math.exp(2))	7.38905609893065
print(math.log(math.e))	1.0
print(math.log10(10))	1.0
print(math.pow(2,3))    8.0#float
print(2**3) 	8#int	
print(math.pow(2,3)==2**3)		True
print(math.sqrt(4))		2.0
print(math.ceil(2.3))	3
print(math.floor(2.3))	2
print(math.modf(2.3))	(0.2999999999999998, 2.0)
print(math.fmod(-1,2))	-1.0
print(math.fmod(1,-2))	1.0

注意区别:

print(-1%2)		1
print(1%-2)		-1
print(math.factorial(5))		120
print(math.sin(math.pi)) 		1.2246467991473532e-16#约等于0	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值