python3学习手册
import math ; math.trunc(xx/yy) 来取整,(xx/yy)可为float,结果 也是整数商 ★小数取整 ①内置函数round()为四舍五入,n.5则靠偶数取整 ROUND_HALF_EVEN round(2.5) #返回2 round(3.5) #返回4 ②math.ceil() 进一法 import math math math.ceil(3.1) #返回4 ③math.floor() 去尾法 import math math.floor(3.99) #返回3 ★二维list 直接定义: matrix = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] 间接定义: matrix = [[0 for i in range(3)] for i in ★math模块 import math x = 2 math.sqrt(x) # 返回x的平方根,float math.pi # 常量 pi=3.141592653589793 math.e # 常量 e=2.718281828459045 math.log(x) # 返回log x的值,以e为底 math.log10(x)0 码力 | 213 页 | 3.53 MB | 1 年前3
共 1 条
- 1