Python中怎么把列表设置为浮点数
要将Python中的列表设置为浮点数,可以使用以下代码:
my_list = [1, 2, 3, 4, 5]
my_list = list(map(float, my_list))
print(my_list)
这里使用了map()函数将每个元素转换为浮点数,然后使用list()函数将返回的map对象转换为列表。输出结果为:
[1.0, 2.0, 3.0, 4.0, 5.0]
原文地址: https://www.cveoy.top/t/topic/hxaB 著作权归作者所有。请勿转载和采集!