讲解对象:math 模块、cmath 模块-数学模块--python 作者:融水公子 rsgz 理解:math 模块、cmath 模块 0.1 Python math 模块提供了许多对浮点数的数学运算函数。 0.2 Python cmath 模块包含了一些用于复数运算的函数。 0.3 cmath 模块的函数跟 math 模块函数基本一致,区别是 cmath 模块运算的是复数,math 模块运算的是数学运算。
看看math包含的内容 >>> import math >>> dir(math) ['__doc__', '__file__', '__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'] >>> 看看cmath包含的内容: >>> import cmath >>> dir(cmath) ['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atanh', 'cos', 'cosh', 'e', 'exp', 'inf', 'infj', 'isclose', 'isfinite', 'isinf', 'isnan', 'log', 'log10', 'nan', 'nanj', 'phase', 'pi', 'polar', 'rect', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau'] >>>
看看实例:
>>> import cmath >>> cmath.sqrt(-1) 1j >>> cmath.sqrt(9) (3+0j) >>> cmath.sin(1) (0.8414709848078965+0j) >>> cmath.log10(100) (2+0j) >>>
分享知识,分享快乐!希望中国站在编程之巅! ----融水公子 公众微信号:rsgz520
360图书馆馆号:rsgz002.360doc.com
|