>>> import math >>> 5**0.5 2.23606797749979 >>> 2**0.5 1.4142135623730951 >>> pow(5, 2) # 内置函数 pow() 25 >>> pow(5, 0.5) # 内置函数 pow() 2.23606797749979 >>> math.pow(5, 2) # 5的2次方 25.0 >>> math.pow(5, 0.5) # 5的0.5次方 2.23606797749979 >>> math.sqrt(5) # 5的开方 2.23606797749979
>>> import math >>> math.hypot(3, 4) # 3、4平方之和的开方 5.0
>>> import math >>> math.log(1024, 2) # 计算以2为底,1024的对数 10.0 >>> math.log(math.e) # 若不指定基数,默认常数e为基数 1.0 >>> math.log1p(math.e-1) # 返回参数+1的对数 1.0 >>> math.log10(100) # 固定底数为10 2.0 >>> math.log2(64) # 固定底数为2 6.0
上一篇:python中int()的作用
下一篇:python怎么输出字符串对齐