Python 列表数据保留5位小数的技巧
在 Python 中,可以使用 round 函数将所有数据舍入为 5 位小数。以下是示例代码:
x0_list = [round(x0, 5)] * len(functions) # 保存初值
x1_list = [round(func(x0_list[j]), 5) for j, func in enumerate(functions)] # 保存x1
在上述代码中,我们使用 round 函数将 x0 和 func(x0) 的结果都舍入为 5 位小数,并将其保存在新的列表中。这样,所有数据都将只保留 5 位小数。
原文地址: https://www.cveoy.top/t/topic/lJtJ 著作权归作者所有。请勿转载和采集!