python 中将列表作为字符串输出
1、
>>> a = [111, 222, 333] >>> "-".join(a) ## 数值类型报错 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sequence item 0: expected str instance, int found >>> "-".join(str(x) for x in a) ## 类型转换 '111-222-333' >>> b = ["aaa", "bbb", "ccc"] >>> "-".join(b) 'aaa-bbb-ccc'