且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中,如何将列表中的所有项目都转换为浮点数?

更新时间:2023-11-28 16:11:22

[float(i) for i in lst]

确切地说,它将创建一个带有浮点值的新列表。与 map 方法不同,它将在py3k中工作。

to be precise, it creates a new list with float values. Unlike the map approach it will work in py3k.