简体   繁体   English

如何将数字列表转换为字符串列表?

[英]How to convert a list of numbers to a list of strings?

I'm knocking my head against a wall regarding adding quotes to a list of numbers.关于在数字列表中添加引号,我将头撞到了墙上。

How do I add single quotes to this list of numbers?如何在此数字列表中添加单引号

num = [1, 2, 3, 4]

Try this:尝试这个:

num = [1, 2, 3, 4]
new_list = [str(i) for i in num]

#output
print(new_list)
['1', '2', '3', '4']
num= list(map(str, num))
print(num)
#output
['1', '2', '3', '4']

here you go: :-)你在这里 go :-)

In [1335]: str(num)                                                                                                                                                                                        
Out[1335]: '[1, 2, 3, 4]'

Try this solution:试试这个解决方案:

    x = [1,2,3,4]
    x = map(lambda x: str(x), x)x = list(x)
    print(x)
    str(x)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM