python 之math模块

一.math 简介

  

import math        # 导入模块

ret = dir(math)    # 查看所有函数名列表
print(ret)
# ['__doc__', '__loader__', '__name__', '__package__', '__spec__',
# 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil',
# 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp',
# 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum',
# 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite',
# 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p',
# 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh',
# 'sqrt', 'tan', 'tanh', 'tau', 'trunc']

ret = help(math)    # 查看具体定义 以及 函数 原型
print(ret)

二.常用函数 简介

 1 acos(x)       # Return the arc cosine (measured in radians) of x.
 2  
 3 asin(x)       # Return the arc sine (measured in radians) of x.
 4  
 5 atan(x)       # Return the arc tangent (measured in radians) of x.
 6  
 7 atan2(y, x)   # Return the arc tangent (measured in radians) of y/x.
 8               # Unlike atan(y/x), the signs of both x and y are considered.
 9  
10 ceil(x)       # Return the ceiling of x as a float.
11               # This is the smallest integral value >= x.
12  
13 cos(x)        # Return the cosine of x (measured in radians).
14  
15 cosh(x)       # Return the hyperbolic(双曲线的) cosine of x.
16  
17 degrees(x)    # converts angle x from radians(弧度) to degrees
18  
19 exp(x)        # Return e raised to the power of x.
20  
21 fabs(x)       # Return the absolute value of the float x.
22  
23 floor(x)      # Return the floor of x as a float.
24               # This is the largest integral value <= x.
25  
26 fmod(x,y)     # Return fmod(x, y), according to platform C.  x % y may differ.
27  
28 frexp(x)      # Return the mantissa and exponent of x, as pair (m, e).
29               # m is a float and e is an int, such that x = m * 2.**e.
30               # If x is 0, m and e are both 0.  Else 0.5 <= abs(m) < 1.0.
31  
32 hypot(x,y)    # Return the Euclidean distance, sqrt(x*x + y*y).
33  
34 ldexp(x, i)   # x * (2**i)
35  
36 log(x[, base])   # the logarithm of x to the given base.
37                  # If the base not specified, returns the natural logarithm (base e) of x.
38  
39 log10(x)      # the base 10 logarithm of x.
40  
41 modf(x)       # Return the fractional and integer parts of x.  Both results carry the sign
42               # of x.  The integer part is returned as a real.
43  
44 pow(x,y)      # Return x**y (x to the power of y).
45  
46 radians(x)    # converts angle x from degrees to radians
47  
48 sin(x)        # Return the sine of x (measured in radians).
49  
50 sinh(x)       # Return the hyperbolic sine of x.
51  
52 sqrt(x)       # Return the square root of x.
53  
54 tan(x)        # Return the tangent of x (measured in radians).
55  
56 tanh(x)       # Return the hyperbolic tangent of x.

 三.该模块定义了两个常量

1 e  = 2.7182818284590451
2 
3 pi = 3.1415926535897931

猜你喜欢

转载自www.cnblogs.com/wenqi2121/p/10388777.html