迪庆州建设局网站,乐潍清网站额建设,php网站开发套模板,网站一般如何做搜索功能1. 前言
math 模块中包含了各种浮点运算函数#xff0c;包括#xff1a;
函数功能floor向下取整ceil向上取整pow指数运算fabs绝对值sqrt开平方modf拆分小数和整数fsum计算列表中所有元素的累加和copysign复制符号pi圆周率e自然对数 2. math.floor(n)
函数 math.floor(n) 的…1. 前言
math 模块中包含了各种浮点运算函数包括
函数功能floor向下取整ceil向上取整pow指数运算fabs绝对值sqrt开平方modf拆分小数和整数fsum计算列表中所有元素的累加和copysign复制符号pi圆周率e自然对数 2. math.floor(n)
函数 math.floor(n) 的功能是对浮点数 n 向下取整示例如下 import mathmath.floor(1.5)
1math.floor(2.5)
2math.floor(-1.5)
-2math.floor(-2.5)
-3函数 math.ceil(n) 的功能是对浮点数 n 向上取整示例如下 import mathmath.ceil(1.5)
2math.ceil(2.5)
3math.ceil(-1.5)
-1math.ceil(-2.5)
-24. math.pow(n, m)
函数 math.pow(n, m) 的功能是指数运算n 是底数m 是指数示例如下 import mathmath.pow(2, 0)
1.0math.pow(2, 1)
2.0math.pow(2, 2)
4.0math.pow(2, 3)
8.0math.pow(2, 4)
16.05. math.fabs(n)
函数 math.fabs(n) 的功能是计算 n 的绝对值示例如下 import mathmath.fabs(1.23)
1.23math.fabs(-1.23)
1.236. math.sqrt(n)
函数 math.sqrt(n) 的功能是计算 n 的平方根示例如下 import mathmath.sqrt(4)
2.0math.sqrt(9)
3.0math.sqrt(16)
4.07. math.modf(n)
函数 math.modf(n) 的功能是将浮点数 n 拆分为小数和整数函数返回一个元组
元组的第 0 项是小数元组的第 1 项是整数
示例如下 import mathmath.modf(3.14)
(0.14, 3.0)tuple math.modf(1949.1001)tuple[0]
0.1001tuple[1]
1949在第 3 行 0.14 是 3.14 的小数部分3.0 是 3.14 的整数部分 在第 6 行0.1001 是 1949.1001 的小数部分在第 6 行1949 是 1949.1001 的整数部分 8. math.fsum(list)
函数 math.fsum(list) 的功能是计算列表中所有元素的累加和示例如下 import mathmath.fsum([1, 2, 3])
6.0math.fsum((1, 2, 3)
6.0在第 2 行计算列表 [1, 2, 3] 中 3 个元素的累加和在第 4 行计算元组 (1, 2, 3) 中 3 个元素的累加和 9. math.copysign(a, b)
函数 math.copysign(a, b) 的功能是将参数 b 的正负符号复制给第一个数示例如下 import mathmath.copysign(2, -1)
-2.0math.copysign(-2, 1)
2.010. math.pi
函数 math.pi 的功能是圆周率常量示例如下 import mathmath.pi
3.14159265358979311. math.e
函数 math.e 的功能是自然对数常量示例如下 import mathmath.e
2.718281828459045