Learning Path
浏览 Python 3 相关教程与章节。
主流编程语言、数据结构、设计模式、正则与基础算法。
教程
728
Python math.cosh() 方法 Python math 模块 Python math.cosh(x) 返回 x 的双曲余弦值,相当于 (exp(number) + exp(-number)) / 2。 Python 版本: 1.4 语法 math.cosh() 方法语法如下: math.cosh(x) 参数说明: x -- 必需,个正数或负数。如果 x 不是一个数字,返回 TypeError。 返回值 ..
Python math.degrees() 方法 Python math 模块 Python math.degrees(x) 方法将角度 x 从弧度转换为度数。 PI (3.14..) 弧度等于 180 度,也就是说 1 弧度等于 57.2957795 度。 math.radians() 方法将度数值转换为弧度。 Python 版本: 2.3 语法 math.degrees() 方法语法如下: math.degrees(x) 参..
Python math.dist() 方法 Python math 模块 Python math.dist(p, q) 方法返回 p 与 q 两点之间的欧几里得距离,以一个坐标序列(或可迭代对象)的形式给出。 两个点必须具有相同的维度。 传入的参数必须是正整数。 Python 版本:3.8 语法 math.dist() 方法语法如下: math.dist(p, q) 参数说明: p -- 必需,指定第一个点。 q -- 必..
Python math.e 常量 Python math 模块 Python math.e 常量用于返回欧拉数 (2.7182...)。 语法 math.e 常量语法如下: math.e 返回值 返回一个浮点数 2.718281828459045,表示数学常数 e。 实例 以下实例返回欧拉数 (2.7182...): 实例 [mycode4 type='python'] # 导入 math 包 impor..
Python math.erf() 方法 Python math 模块 Python math.erf(x) 方法返回一个数的误差函数 math.erf(x) 方法接受 - inf 和 + inf 之间的值,并返回 - 1 到 + 1 之间的值。 Python 版本:3.2 语法 math.erf() 方法语法如下: math.erf(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 ..
Python math.erfc() 方法 Python math 模块 Python math.erfc(x) 方法返回 x 处的互补误差函数。 math.erfc(x) 方法接受 - inf 和 + inf 之间的值,并返回 - 1 到 + 1 之间的值。 Python 版本: 3.2 语法 math.erfc() 方法语法如下: math.erfc(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 T..
Python math.exp() 方法 Python math 模块 Python math.exp(x) 方法返回 e 的 x 次幂(次方)Ex,其中 e = 2.718281... 是自然对数的基数。 Python 版本:1.6.1 语法 math.exp() 方法语法如下: math.exp(x) 参数说明: x -- 必需,数字,指定指数。如果 x 不是一个数字,返回 TypeError。 返回值 一个浮点..
Python math.exp2() 函数 Python math 模块 在科学计算和计算机领域,2 的幂(powers of 2)是最基础的指数运算之一。无论是算法复杂度分析、密码学、还是计算机存储单位,都离不开 2 的幂次计算。 math.exp2() 是 Python 3.11 引入的函数,专门用于计算 2 的 x 次幂,即 2ˣ。 单词释义: exp2 是 'exponential base 2' 的缩写..
Python math.expm1() 方法 Python math 模块 Python math.expm1(x) 方法返回 e 的 x 次幂(次方)减 1,Ex - 1,其中 e = 2.718281... 是自然对数的基数。 math.expm1(x) 方法比调用 math.exp() 减去 1 更精确。 Python 版本:2.7 语法 math.expm1() 方法语法如下: math.expm1(x) 参数说明: ..
Python math.fabs() 方法 Python math 模块 Python math.fabs(x) 方法返回 x 的绝对值。 绝对值是非负数,有负号会删除。 与 Python 内置的 abs() 不同,此方法始终将值转换为浮点值。 语法 math.fabs() 方法语法如下: math.fabs(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 返回值 返回一个..
Python math.factorial() 方法 Python math 模块 Python math.factorial(x) 方法返回 x 的阶乘。 参数只能是正整数。 一个数字的阶乘是所有整数的乘积之和,例如,6 的阶乘是: 6 x 5 x 4 x 3 x 2 x 1 = 720。 语法 math.factorial() 方法语法如下: math.factorial(x) 参数说明: x -- 必需,正整数。如果数..
Python math.floor() 方法 Python math 模块 Python math.floor(x) 方法将 x 向下舍入到最接近的整数。 math.ceil() 方法将数字向上舍入到最接近的整数。 语法 math.floor() 方法语法如下: math.floor(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 返回值 返回一个整数 int,表示向下舍..
Python math.fmod() 方法 Python math 模块 Python math.fmod(x, y) 方法返回 x/y 的余数。 Python 版本:2.7 语法 math.fmod() 方法语法如下: math.fmod(x, y) 参数说明: x -- 必需,正数或负数。被除数。如果 x 不是一个数字,返回 TypeError。 y -- 必需,正数或负数。除数。如果 y 不是一个数字,返回 Type..
Python math.frexp() 方法 Python math 模块 Python math.frexp(x) 方法以 (m, e) 对的形式返回 x 的尾数和指数。 该方法的数学公式为: number = m * 2**e。 Python 版本:2.6 语法 math.frexp() 方法语法如下: math.frexp(x) 参数说明: x -- 必需,正数或负数。如果 x 不是一个数字,返回 TypeError。..
Python math.fsum() 方法 Python math 模块 Python math.fsum(iterable) 方法计算可迭代对象 (元组, 数组, 列表, 等)中的元素的总和。 Python 版本:2.6 语法 math.fsum() 方法语法如下: math.fsum(iterable) 参数说明: iterable -- 必需,可迭代对象,可以是列表、元组、数组。如果可迭代对象元素不是数字,返回 Ty..
Python math.gamma() 方法 Python math 模块 Python math.gamma(x) 方法返回 x 处的伽玛函数(Gamma 函数)。 伽玛函数,也叫欧拉第二积分,是阶乘函数在实数与复数上扩展的一类函数。 要查找数字的对数伽玛值,请使用 math.lgamma() 方法。 Python 版本: 3.2 语法 math.gamma() 方法语法如下: math.gamma(x) 参数说明: x ..
Python math.gcd() 方法 Python math 模块 Python math.gcd() 方法返回给定的整数参数的最大公约数。 gcd(0,0) 返回 0。 Python 版本:3.5 在 3.9 版更改: 添加了对任意数量的参数的支持,之前的版本只支持两个参数。 语法 math.gcd() 方法语法如下: math.gcd(*integers) 参数说明: *integers -- 必需,数字。如果 x ..
Python math.hypot() 方法 Python math 模块 Python math.hypot() 方法返回欧几里得范数。 欧几里得范数是从原点到给定坐标的距离。 欧几里得度量又称为欧几里得距离,指的是欧几里得空间中两点间“普通”(即直线)距离。 在 Python 3.8 之前,此方法用于查找直角三角形的斜边:sqrt(x*x + y*y)。 从 Python 3.8 开始,此方法也用于计算欧几里得范数。 对于 ..
Python math.inf 常量 Python math 模块 Python math.inf 正无穷大的浮点数,负无穷大,使用 -math.inf 。 math.inf 相当于 float('inf') 的输出。 语法 math.inf 常量语法如下: math.inf 返回值 返回一个浮点数,表示正无穷大。 实例 以下实例返回正无穷大与负无穷大: 实例 [mycode4 type='pyt..
Python math.isclose() 方法 Python math 模块 Python math.isclose() 方法返回用于检查两个值是否彼此接近,如果值接近,则返回 True,否则返回 False。 math.isclose() 根据给定的绝对和相对容差确定两个值是否被认为是接近的。 Python 版本:3.5 计算公式为: abs(a-b)..
Python math.isfinite() 方法 Python math 模块 Python math.isfinite() 方法判断 x 是否有限,如果 x 既不是无穷大也不是 NaN,则返回 True ,否则返回 False 。 Python 版本:3.2 语法 math.isfinite() 方法语法如下: math.isfinite(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeE..
Python math.isinf() 方法 Python math 模块 Python math.isinf() 方法判断 x 是否是无穷大,如果 x 是正或负无穷大,则返回 True ,否则返回 False 。 Python 版本:2.6 语法 math.isinf() 方法语法如下: math.isinf(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 返回值 返..
Python math.isnan() 方法 Python math 模块 Python math.isnan() 方法判断数字是否为 NaN(非数字),如果数字是 NaN(不是数字),则返回 True ,否则返回 False 。 Python 版本: 3.5 语法 math.isnan() 方法语法如下: math.isnan(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 ..
Python math.isqrt() 方法 Python math 模块 Python math.isqrt(x) 方法返回 x 的平方根,并将平方根数向下舍入到最接近的整数。 数字必须大于等于 0。 Python 版本:3.8 语法 math.isqrt() 方法语法如下: math.isqrt(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果数字小于 0,则返回 ValueE..