python 中如何将列表中的数值转换为字符串

 

001、

>>> test1 = ["aaa", 100, 200]
>>> test1
['aaa', 100, 200]
>>> test2 = [str(k) for k in test1]      ## 将列表test1中的数值转换为字符串
>>> test2
['aaa', '100', '200']

 

002、

>>> test1 = ("aaa", 100, 200)
>>> test1
('aaa', 100, 200)
>>> test2 = [str(k) for k in test1]        ## 同样适用于元组
>>> test2
['aaa', '100', '200']
>>> tuple(test2)
('aaa', '100', '200')

 

posted @ 2022-08-18 08:27  小鲨鱼2018  阅读(477)  评论(0编辑  收藏  举报