【发布时间】:2018-12-24 14:54:56
【问题描述】:
我在下面列出了多种数据类型(字符串和整数)。如何将其转换为字符串。
sample_list =['a','b',1,'c',2,4,'d']
以下语句无效。
' '.join(sample_list)
【问题讨论】:
-
因为您的列表包含
int类型,您必须在join之前将其转换为字符串。
标签: python python-3.x python-2.7
我在下面列出了多种数据类型(字符串和整数)。如何将其转换为字符串。
sample_list =['a','b',1,'c',2,4,'d']
以下语句无效。
' '.join(sample_list)
【问题讨论】:
int 类型,您必须在join 之前将其转换为字符串。
标签: python python-3.x python-2.7
' '.join(map(str, sample_list))
【讨论】: