python中list与tuple转化及三种小数取整方式

来源:互联网 发布:ncp1337p各脚电压数据 编辑:程序博客网 时间:2024/05/22 06:13

以list作为参数将tuple类初始化,将返回tuple类型

tuple([1,2,3]) #list转换为tuple

以tuple作为参数将list类初始化,将返回list类型

list((1,2,3)) #tuple转换为list

向上取整

print("math.ceil(4.4) => ", math.ceil(4.4))    print("math.ceil(4.7) => ", math.ceil(4.7))   

向下取整

print("math.floor(4.4) => ", math.floor(4.4))    print("math.floor(4.7) => ", math.floor(4.7))    

四舍五入

print("round(4.4) => ", round(4.4))   print("round(4.7) => ", round(4.7))