zoukankan      html  css  js  c++  java
  • 一月5日

    Python math 模块、cmath 模块

    Python 中数学运算常用的函数基本都在 math 模块、cmath 模块中。

    Python math 模块提供了许多对浮点数的数学运算函数。

    Python cmath 模块包含了一些用于复数运算的函数。

    cmath 模块的函数跟 math 模块函数基本一致,区别是 cmath 模块运算的是复数,math 模块运算的是数学运算。

    要使用 math 或 cmath 函数必须先导入:

    import 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)
    >>>
  • 相关阅读:
    学习笔记(4)---JQuery
    学习笔记---ES6
    angular.js的学习笔记(1)
    vue.js学习笔记(1)
    HTML5“爱心鱼”游戏总结
    学习笔记(3)---综合
    学习笔记(2)---CSS中的易混淆点
    学习笔记(1)----水平垂直居中的方法
    javascript:void(0)是什么意思
    private Int32? m_shopid;
  • 原文地址:https://www.cnblogs.com/zxpnb/p/14235997.html
Copyright © 2011-2022 走看看