python中的math跟java里面的math类很像
用math得到pi的值
>>> import math
>>> print(math.pi)
3.141592653589793
用math求sin函数
>>> print(math.sin(math.pi/6))
0.49999999999999994
用math求cos函数
>>> print(math.cos(math.pi/3))
0.5000000000000001
用math求方pow,跟**一样
>>> print(math.pow(2,4))
16.0
>>> print(2**4)
16
这里有点不同的原因是math的pow的返回值是floa类型的,而2**3的结果是整型的
其他还是很多的math的函数:
>>> help(math)
Help on built-in module math:
NAME
math
DESCRIPTION
This module is always available. It provides access to the
mathematical functions defined by the C standard.
FUNCTIONS
acos(...)
acos(x)
Return the arc cosine (measured in radians) of x.
acosh(...)
acosh(x)
Return the inverse hyperbolic cosine of x.
asin(...)
asin(x)
Return the arc sine (measured in radians) of x.
asinh(...)