Learning Path
浏览 Python 3 相关教程与章节。
主流编程语言、数据结构、设计模式、正则与基础算法。
教程
728
Python math.lcm() 函数 Python math 模块 在数论中,最小公倍数(Least Common Multiple,简称 LCM)是一个非常重要的概念。它用于找到两个或多个整数的共同倍数中最小的那一个。 math.lcm() 是 Python 3.9 引入的函数,专门用于计算多个整数的最小公倍数(LCM)。 单词释义: lcm 是 'Least Common Multiple' 的缩写,意为..
Python math.ldexp() 方法 Python math 模块 Python math.ldexp(x, i) 方法返回 x * (2**i),math.frexp() 的反函数。 Python 版本:2.6 语法 math.ldexp() 方法语法如下: math.ldexp(x, i) 参数说明: x -- 必需,一个正数或负数。如果值不是数字,则返回 TypeError。 i -- 必需,一个正数或负数..
Python math.lgamma() 方法 Python math 模块 Python math.lgamma(x) 方法返回一个数字的自然对数伽玛值。 我们也可以通过使用 math.gamma() 方法找到伽玛值,然后使用 math.log() 方法计算该值的自然对数。 伽玛值等于 factorial(x-1)。 Python 版本: 3.2 语法 math.lgamma() 方法语法如下: math.lgamma(x) ..
Python math.log() 方法 Python math 模块 Python math.log(x) 方法使用一个参数,返回 x 的自然对数(底为 e )。 语法 math.log() 方法语法如下: math.log(x[, base]) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果值为 0 或负数,则返回 ValueError。 base -- 可选,底数,默认为 ..
Python math.log10() 方法 Python math 模块 Python math.log10(x) 方法返回 x 以 10 为底的对数。 语法 math.log10() 方法语法如下: math.log10(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果值为 0 或负数,则返回 ValueError。 返回值 返回一个整数浮点数 float,表示一..
Python math.log1p() 方法 Python math 模块 Python math.log1p(x) 方法返回 1+x 的自然对数(以 e 为底)。 语法 math.log1p() 方法语法如下: math.log1p(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果值为 0 或负数,则返回 ValueError。 返回值 返回一个整数浮点数 floa..
Python math.log2() 方法 Python math 模块 Python math.log2(x) 方法返回 x 以 2 为底的对数。 语法 math.log2() 方法语法如下: math.log2(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果值为 0 或负数,则返回 ValueError。 返回值 返回一个整数浮点数 float,表示一个数字以 ..
Python math.modf() 函数 Python math 模块 在数值计算中,有时我们需要分离一个数字的整数部分和小数部分。例如,从 3.14 中提取出 3 和 0.14。 math.modf() 就是专门用于执行这一操作的函数,它返回一个元组,包含数字的小数部分和整数部分。 单词释义: modf 是 'modular fractional' 的缩写,意为'小数部分'。 基本语法..
Python math.nan 常量 Python math 模块 Python math.nan 返回一个浮点值 nan(not a number,不是一个数字),这个值不是一个合法数字。 math.nan 相当于 float('nan') 的输出。 语法 math.nan 常量语法如下: math.nan 返回值 返回一个浮点数 nan。 实例 以下实例返回 nan: 实例 [mycode4 type=..
Python math.nextafter() 函数 Python math 模块 在浮点数计算中,了解相邻浮点数之间的关系非常重要。计算机中的浮点数是离散的,相邻两个浮点数之间有一个最小的间隔。 math.nextafter() 是 Python 3.9 引入的函数,用于返回从 x 朝 y 方向前进指定浮点步数后的值。 单词释义: nextafter 意为'下一个之后'。 基本语法与参数 语法格式 imp..
Python math.perm() 方法 Python math 模块 Python math.perm(x, i) 方法返回不重复且有顺序地从 n 项中选择 k 项的方式总数。 注意:k 参数是可选的。 如果我们没有设置 k,这个方法将返回 n! (例如,math.perm(7) 将返回 5040)。 Python 版本:3.8 语法 math.perm() 方法语法如下: math.perm(n, k) 参数说明: x ..
Python math.pi 常量 Python math 模块 Python math.pi 返回一个浮点值 π, 一般指圆周率,圆周率 PI (3.1415...)。 PI: 3.141592653589793。 语法 math.pi 常量语法如下: math.pi 返回值 返回一个浮点数 3.141592653589793,表示圆周率。 实例 以下实例返回 PI: 实例 [mycode4 type='pyth..
Python math.pow() 方法 Python math 模块 Python math.pow(x, y) 方法返回返回 x 的 y 次幂( 次方 )。 如果 x 为负且 y 不是整数,则返回 ValueError。 该方法会将两个参数转换为浮点数。 math.pow(1.0,x) 或 math.pow(x,0.0),始终返回 1.0。 语法 math.pow() 方法语法如下: math.pow(x, y) 参数说明: ..
Python math.prod() 方法 Python math 模块 Python math.prod() 方法用于计算可迭代对象中所有元素的积。 Python 版本:3.8 语法 math.prod() 方法语法如下: math.prod(iterable, start) 参数说明: iterable -- 必需,可迭代对象。 start -- 可选,指起始值。 默认值为 1。 返回值 一个浮点值或整数,可迭代..
Python math.radians() 方法 Python math 模块 Python math.radians(x) 方法将角度 x 从度数转换为弧度。 math.degrees() 方法将弧度值转换为度数。 Python 版本: 2.0 语法 math.radians() 方法语法如下: math.radians(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。 ..
Python math.remainder() 方法 Python math 模块 Python mathremainder(x, y) 方法返回 x/y 的余数。 Python 版本:3.7 语法 math.remainder() 方法语法如下: math.remainder(x, y) 参数说明: x -- 必需,被除数。 y -- 可选,除数。必须是非零数字,否则会发生 ValueError。 返回值 一个浮点值..
Python math.sin() 方法 Python math 模块 Python math.sin(x) 返回 x 弧度的正弦值。 要获取指定角度的正弦,必须首先使用 math.radians() 方法将其转换为弧度。 Python 版本: 1.4 语法 math.sin() 方法语法如下: math.sin(x) 参数说明: x -- 必需,数字。如果 x 不是数字,则返回 TypeError。 返回值 返..
Python math.sinh() 方法 Python math 模块 Python math.sinh(x) 返回 x 的双曲正弦值。 Python 版本: 1.4 语法 math.sinh() 方法语法如下: math.sinh(x) 参数说明: x -- 必需,个正数或负数。如果 x 不是一个数字,返回 TypeError。 返回值 返回一个浮点数,表示一个数字的双曲正弦值。 实例 以下实例返回不同数字的双..
Python math.sqrt() 函数 Python math 模块 Python math.sqrt(x) 函数返回 x 的平方根。 数字必须大于等于 0。 语法 math.sqrt() 函数语法如下: math.sqrt(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError。如果数字小于 0,则返回 ValueError。 返回值 返回一个浮点数,表示一个数的平方根。 实..
Python math.tan() 方法 Python math 模块 Python math.tan(x) 返回 x 弧度的正切值。 Python 版本: 1.4 语法 math.tan() 方法语法如下: math.tan(x) 参数说明: x -- 必需,数字。如果 x 不是数字,则返回 TypeError。 返回值 返回一个浮点数,表示 x 的正切值。 实例 以下实例返回数字的正切值: 实例 [my..
Python math.tanh() 方法 Python math 模块 Python math.tanh(x) 返回 x 的双曲正切值。 Python 版本: 1.4 语法 math.tanh() 方法语法如下: math.tanh(x) 参数说明: x -- 必需,个正数或负数。如果 x 不是一个数字,返回 TypeError。 返回值 返回一个浮点数,表示一个数字的双曲正切值。 实例 以下实例返回不同数字的双..
Python math.tau 常量 Python math 模块 Python math.tau 返回数学常数 τ = 6.283185..., tau 是一个圆周常数,等于 2π,圆的周长与半径之比。 tau 值为 6.283185307179586。 语法 math.tau 常量语法如下: math.tau 返回值 返回一个浮点数 6.283185307179586,表示圆的周长与半径之比。 实例 以下实例返回 tau: ..
Python math.trunc() 方法 Python math 模块 Python math.trunc(x) 方法返回 x 截断整数的部分,即返回整数部分,忽略小数部分。 math.trunc(x) 方法不会将数字向上/向下舍入到最接近的整数,而只是删除小数。 语法 math.trunc() 方法语法如下: math.trunc(x) 参数说明: x -- 必需,数字。如果 x 不是一个数字,返回 TypeError..
Python math.ulp() 函数 Python math 模块 在浮点数计算中,理解浮点数的精度限制非常重要。ULP(Unit in the Last Place)是衡量浮点数精度的基本单位。 math.ulp() 是 Python 3.9 引入的函数,用于返回浮点数的最小有效浮点单位(ULP),即从该数到下一个可表示浮点数之间的距离。 单词释义: ulp 是 'Unit in the Last Place..