python出现float()argument must be a string or a number,not ‘map‘的错误问题及解决

 更新时间:2026年06月23日 14:04:29   作者:coding上下求索  
这段文章主要讲解了在使用Python的`map()`函数后,如何正确转换数据以避免`TypeError: float() argument must be a string or ornot map()`错误,建议将`map()`函数后的数据转换为`list`再进行浮点数转换

python出现float()argument must be a string or a number,not ‘map‘

报错

TypeError: float() argument must be a string or a number, not 'map'

这时候,首先你肯定是用了map()这个函数,

不管你用map这个函数把数据转变成了什么格式,

不管是int还是float还是其它的,

最后,你要把map完的数据转换成list,

如果你要是需要array的话,可以再转换成array,但是要套在list外面。

简单来说

最简单的解决这个报错的方法是这样,找到你用map函数的位置,

改成下面这样;

x = list(map())

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

最新评论