講解對(duì)象:math 模塊、cmath 模塊-數(shù)學(xué)模塊--python 作者:融水公子 rsgz 理解:math 模塊、cmath 模塊 0.1 Python math 模塊提供了許多對(duì)浮點(diǎn)數(shù)的數(shù)學(xué)運(yùn)算函數(shù)。 0.2 Python cmath 模塊包含了一些用于復(fù)數(shù)運(yùn)算的函數(shù)。 0.3 cmath 模塊的函數(shù)跟 math 模塊函數(shù)基本一致,區(qū)別是 cmath 模塊運(yùn)算的是復(fù)數(shù),math 模塊運(yùn)算的是數(shù)學(xué)運(yùn)算。
看看math包含的內(nèi)容 >>> 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包含的內(nèi)容: >>> 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'] >>>
看看實(shí)例:
>>> import cmath >>> cmath.sqrt(-1) 1j >>> cmath.sqrt(9) (3+0j) >>> cmath.sin(1) (0.8414709848078965+0j) >>> cmath.log10(100) (2+0j) >>>
分享知識(shí),分享快樂!希望中國(guó)站在編程之巔! ----融水公子 公眾微信號(hào):rsgz520
360圖書館館號(hào):rsgz002.360doc.com
|