我有一个['this', 'that']
形式的字符串数组。
我需要在结尾处输入一个字符串:
('this', 'that')
我知道我可以用.join()获取逗号,如何以最优雅的方式获取每个项目的引号?
答案 0 :(得分:3)
与 vaultah 一样,使用repr()
来计算对象的字符串表示。
例如,
如果array = ['this', 'that', 'is', 'the', 'input']
然后array = repr(tuple(array))
将导致:('this', 'that', 'is', 'the', 'input')