【发布时间】:2020-07-10 05:32:55
【问题描述】:
我有一个包含数字和字符串的列表:
words = ['hello', 2, 3, 4, 5]
我想要一个字符串:
"'hello', 2, 3, 4, 5"
用 Python 最简单的方法是什么
【问题讨论】:
-
这能回答你的问题吗? printing double quotes around a variable
-
如果存在另一个字符串,您希望发生什么?例如
words = ['hello', 2, 3, 'there', 5]?如果words = [1, 2, 'hello', 4, 5]转换任何字符串或仅转换第一个元素怎么办? -
words = ['hello', 2, 3, 'there', 5]这也是可能的 或者words = ['hello',' 2', '3', '4', '5']在这一个中,我必须更改第一个不是数字的。
标签: python-3.x string list