python列表中的所有值转换为字符串,以及列表拼接成一个字符串

>>> ls1 = ['a', 1, 'b', 2]
>>> ls2 = [str(i) for i in ls1]
>>> ls2
['a', '1', 'b', '2']
>>> ls3 = ''.join(ls2)
>>> ls3
'a1b2'

  

猜你喜欢

转载自www.cnblogs.com/kevenwork/p/10329634.html
今日推荐