首先使用将整数转换为字符串str
using map
函数然后使用join
功能-
>>> ','.join(map(str,[10,"test",10.5]) )#since added comma inside the single quote output will be comma(,) separated
>>> '10,test,10.5'
或者,如果您想将列表的每个元素转换为字符串,请尝试-
>>> map(str,[10,"test",10.5])
>>> ['10', 'test', '10.5']
Or use itertools
内存效率(大数据)
>>>from itertools import imap
>>>[i for i in imap(str,[10,"test",10.5])]
>>>['10', 'test', '10.5']
或者简单地使用列表理解
>>>my_list=['10', 'test', 10.5]
>>>my_string_list=[str(i) for i in my_list]
>>>my_string_list
>>>['10', 'test', '10.5']