从数组构建Python字符串

时间:2016-03-17 16:10:51

标签: python python-3.x

我有一个['this', 'that']形式的字符串数组。

我需要在结尾处输入一个字符串:

('this', 'that')

我知道我可以用.join()获取逗号,如何以最优雅的方式获取每个项目的引号?

1 个答案:

答案 0 :(得分:3)

vaultah 一样,使用repr()来计算对象的字符串表示。

例如,

如果array = ['this', 'that', 'is', 'the', 'input']

然后array = repr(tuple(array))

将导致:('this', 'that', 'is', 'the', 'input')