math库用法非常丰富,涵盖了数学中公式用法。
1、log用法
源码:
示例代码:
import math
a = 2
b = 8
ret1 = math.log(a, b)
print(ret1)
ret2 = math.log(b, a)
print(ret2)
运行结果:
2、log2用法
源码:
示例代码:
import math
a = 2
b = 8
ret1 = math.log2(a)
print(ret1)
ret2 = math.log2(b)
print(ret2)
运行结果:
参考博文:
【python】math函数库介绍及其例题_python中math函数库