对list中string类型数据,全部转为int或者float。
代码如下
- str转int
if __name__ == '__main__': strList=['222','333','444'] intList = list(map(int, strList)) print(intList)
- str转float
if __name__ == '__main__': strList=['222','333','444'] floatList = list(map(float,strList)) print(floatList)