python中字符串list转化为数值型

之前在网上找相关的资料,给出的方法都不合适,

经过很长时间的试错才知道源于python2.X和python3.X的不同,

原理都是采用map函数,但是二者返回的信息不同

Python2.x,可以使用map函数

1
numbers = map(int, numbers)

如果是3.x,map返回的是map对象,当然也可以转换为List:

1
numbers = list(map(int, numbers))

所以这里需要区别对待;

链接:http://www.jb51.net/article/86561.htm

posted @ 2017-04-16 12:20  成为数据分析熟手  阅读(34441)  评论(0编辑  收藏  举报