Python教程
Python 基础手册
Python 英语
Python 简介
Python 入门
Python 语法
Python 注释
Python 变量
Python 关键字
Python 快捷键
Python 数据类型
Python 布尔
Python 运算符
Python 占位符
Python If语句
Python For循环
Python While循环
Python 数字
Python 字符串
字符串 capitalize()
字符串 casefold()
字符串 center()
字符串 count()
字符串 encode()
字符串 endswith()
字符串 expandtabs()
字符串 find()
字符串 format()
字符串 format_map()
字符串 index()
字符串 isalnum()
字符串 isalpha()
字符串 isdecimal()
字符串 isdigit()
字符串 isidentifier()
字符串 islower()
字符串 isnumeric()
字符串 isprintable()
字符串 isspace()
字符串 istitle()
字符串 isupper()
字符串 join()
字符串 ljust()
字符串 lower()
字符串 lstrip()
字符串 maketrans()
字符串 partition()
字符串 replace()
字符串 rfind()
字符串 rindex()
字符串 rjust()
字符串 rpartition()
字符串 rsplit()
字符串 rstrip()
字符串 split()
字符串 splitlines()
字符串 startswith()
字符串 strip()
字符串 swapcase()
字符串 title()
字符串 translate()
字符串 upper()
字符串 zfill()
Python 列表
列表 append()
列表 clear()
列表 copy()
列表 count()
列表 extend()
列表 index()
列表 insert()
列表 pop()
列表 remove()
列表 reverse()
列表 sort()
Python 数组
Python 元组
元组 count()
元组 index()
Python 集合
集合 add()
集合 clear()
集合 copy()
集合 difference()
集合 difference_update()
集合 discard()
集合 intersection()
集合 intersection_update()
集合 isdisjoint()
集合 issubset()
集合 issuperset()
集合 pop()
集合 remove()
集合 symmetric_difference()
集合 symmetric_difference_update()
集合 union()
集合 update()
Python 字典
字典 clear()
字典 copy()
字典 fromkeys()
字典 get()
字典 items()
字典 keys()
字典 pop()
字典 popitem()
字典 setdefault()
字典 update()
字典 values()
Python 函数
内建函数 abs()
内建函数 all()
内建函数 any()
内建函数 ascii()
内建函数 bin()
内建函数 bool()
内建函数 bytearray()
内建函数 bytes()
内建函数 callable()
内建函数 chr()
内建函数 classmethod()
内建函数 compile()
内建函数 complex()
内建函数 delattr()
内建函数 dict()
内建函数 dir()
内建函数 divmod()
内建函数 enumerate()
内建函数 eval()
内建函数 exec()
内建函数 filter()
内建函数 float()
内建函数 format()
内建函数 frozenset()
内建函数 getattr()
内建函数 globals()
内建函数 hasattr()
内建函数 hash()
内建函数 help()
内建函数 hex()
内建函数 id()
内建函数 input()
内建函数 int()
内建函数 isinstance()
内建函数 issubclass()
内建函数 iter()
内建函数 len()
内建函数 list()
内建函数 locals()
内建函数 map()
内建函数 max()
内建函数 memoryview()
内建函数 min()
内建函数 next()
内建函数 object()
内建函数 oct()
内建函数 open()
内建函数 ord()
内建函数 pow()
内建函数 print()
内建函数 property()
内建函数 range()
内建函数 repr()
内建函数 reversed()
内建函数 round()
内建函数 set()
内建函数 setattr()
内建函数 slice()
内建函数 sorted()
内建函数 @staticmethod()
内建函数 str()
内建函数 sum()
内建函数 super()
内建函数 tuple()
内建函数 type()
内建函数 vars()
内建函数 zip()
Python 类和对象
Python 继承
Python 迭代器
Python 作用域
Python 模块
Python 日期
Python JSON
Python 正则表达式
Python PIP
Python Try Except
Python 命令行输入
Python 文件处理
文件处理 close()
文件处理 detach()
文件处理 fileno()
文件处理 flush()
文件处理 isatty()
文件处理 read()
文件处理 readable()
文件处理 readline()
文件处理 readlines()
文件处理 seek()
文件处理 seekable()
文件处理 tell()
文件处理 truncate()
文件处理 writeable()
文件处理 write()
文件处理 writelines()
Python 模块手册
Python 随机模块(Random)
Python OS模块
Python 请求模块(Requests)
Requests.delete()
Requests.get()
Requests.head()
Requests.post()
Python 数学模块(cmath)
Python math模块
Python 网络爬虫
HTTP 教程
HTTP/HTTPS 简介
HTTP 消息结构
HTTP 请求方法
HTTP 响应头信息
HTTP 状态码
Python 实例练习
练习001.算术运算
练习002.数字阶乘
练习003.计算面积
练习004.求取素数
练习005.计算平方
练习006.列表求和
练习007.数字偶数
练习008.列表删除
练习009.列表去重
练习010.列表排序
练习011.文件读写
练习012.计算分数
本文档使用 MrDoc 发布
-
+
首页
Python math模块
## Python math 模块 Python math 模块提供了许多对浮点数的数学运算函数。 math 模块下的函数,返回值均为浮点数,除非另有明确说明。 如果你需要计算复数,请使用 cmath 模块中的同名函数。 要使用 math 函数必须先导入: ``` import math ``` **查看 math 模块中的内容:** ``` >>> import math >>> dir(math) ['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp'] ``` ### math 模块常量 | 常量 | 描述 | | --- | --- | | math.e | 返回欧拉数 (2.7182...) | | math.inf | 返回正无穷大浮点数 | | math.nan | 返回一个浮点值 NaN (not a number) | | math.pi | π 一般指圆周率。 圆周率 PI (3.1415...) | | math.tau | 数学常数 τ = 6.283185...,精确到可用精度。Tau 是一个圆周常数,等于 2π,圆的周长与半径之比。 | ### math 模块方法 | 方法 | 描述 | | --- | --- | | math.acos(x) | 返回 x 的反余弦,结果范围在 0 到 pi 之间。 | | math.acosh(x) | 返回 x 的反双曲余弦值。 | | math.asin(x) | 返回 x 的反正弦值,结果范围在 -pi/2 到 pi/2 之间。 | | math.asinh(x) | 返回 x 的反双曲正弦值。 | | math.atan(x) | 返回 x 的反正切值,结果范围在 -pi/2 到 pi/2 之间。 | | math.atan2(y, x) | 返回给定的 X 及 Y 坐标值的反正切值,结果是在 -pi 和 pi 之间。 | | math.atanh(x) | 返回 x 的反双曲正切值。 | | math.ceil(x) | 将 x 向上舍入到最接近的整数 | | math.comb(n, k) | 返回不重复且无顺序地从 n 项中选择 k 项的方式总数。 | | math.copysign(x, y) | 返回一个基于 x 的绝对值和 y 的符号的浮点数。 | | math.cos() | 返回 x 弧度的余弦值。 | | math.cosh(x) | 返回 x 的双曲余弦值。 | | math.degrees(x) | 将角度 x 从弧度转换为度数。 | | math.dist(p, q) | 返回 p 与 q 两点之间的欧几里得距离,以一个坐标序列(或可迭代对象)的形式给出。 两个点必须具有相同的维度。 | | math.erf(x) | 返回一个数的误差函数 | | math.erfc(x) | 返回 x 处的互补误差函数 | | math.exp(x) | 返回 e 的 x 次幂,Ex, 其中e =2.718281... 是自然对数的基数。 | | math.expm1() | 返回 Ex - 1, e 的 x 次幂,Ex,其中 e = 2.718281... 是自然对数的基数。这通常比 math.e ** x 或 pow(math.e, x) 更精确。 | | math.fabs(x) | 返回 x 的绝对值。 | | math.factorial(x) | 返回 x 的阶乘。 如果 x 不是整数或为负数时则将引发 ValueError。 | | math.floor() | 将数字向下舍入到最接近的整数 | | math.fmod(x, y) | 返回 x/y 的余数 | | math.frexp(x) | 以 (m, e) 对的形式返回 x 的尾数和指数。 m 是一个浮点数, e 是一个整数,正好是 x == m * 2**e 。 如果 x 为零,则返回 (0.0, 0) ,否则返回 0.5 <= abs(m) < 1 。 | | math.fsum(iterable) | 返回可迭代对象 (元组, 数组, 列表, 等)中的元素总和,是浮点值。 | | math.gamma(x) | 返回 x 处的伽马函数值。 | | math.gcd() | 返回给定的整数参数的最大公约数。 | | math.hypot() | 返回欧几里得范数,sqrt(sum(x**2 for x in coordinates))。 这是从原点到坐标给定点的向量长度。 | | math.isclose(a,b) | 检查两个值是否彼此接近,若 a 和 b 的值比较接近则返回 True,否则返回 False。。 | | math.isfinite(x) | 判断 x 是否有限,如果 x 既不是无穷大也不是 NaN,则返回 True ,否则返回 False 。 | | math.isinf(x) | 判断 x 是否是无穷大,如果 x 是正或负无穷大,则返回 True ,否则返回 False 。 | | math.isnan() | 判断数字是否为 NaN,如果 x 是 NaN(不是数字),则返回 True ,否则返回 False 。 | | math.isqrt() | 将平方根数向下舍入到最接近的整数 | | math.ldexp(x, i) | 返回 x * (2**i) 。 这基本上是函数 math.frexp() 的反函数。 | | math.lgamma() | 返回伽玛函数在 x 绝对值的自然对数。 | | math.log(x[, base]) | 使用一个参数,返回 x 的自然对数(底为 e )。 | | math.log10(x) | 返回 x 底为 10 的对数。 | | math.log1p(x) | 返回 1+x 的自然对数(以 e 为底)。 | | math.log2(x) | 返回 x 以 2 为底的对数 | | math.perm(n,k=None) | 返回不重复且有顺序地从 n项中选择 k项的方式总数。| | math.pow(x, y) | 将返回 x 的 y 次幂。 | | math.prod(iterable) | 计算可迭代对象中所有元素的积。 | | math.radians(x) | 将角度 x 从度数转换为弧度。 | | math.remainder(x, y) | 返回 IEEE 754 风格的 x 除于 y 的余数。 | | math.sin(x) | 返回 x 弧度的正弦值。 | | math.sinh(x) | 返回 x 的双曲正弦值。 | | math.sqrt(x) | 返回 x 的平方根。 | | math.tan(x) | 返回 x 弧度的正切值。 | | math.tanh(x) | 返回 x 的双曲正切值。 | | math.trunc(x) | 返回 x 截断整数的部分,即返回整数部分,删除小数部分 |
admin
2025年4月23日 22:43
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
Markdown文件
分享
链接
类型
密码
更新密码