python中map函数的用法
python中map函数的用法
001、批量转换数据类型
>>> str1 ## 测试字符串 '123456789' >>> for i in str1[5:]: ... print(i, type(i)) ... 6 <class 'str'> ## 迭代输出为字符型 7 <class 'str'> 8 <class 'str'> 9 <class 'str'> >>> for i in map(int, str1[5:]): ## 利用map批量转换为int型 ... print(i, type(i)) ... 6 <class 'int'> 7 <class 'int'> 8 <class 'int'> 9 <class 'int'>
。