2016-03-17 158 views
1

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

我需要的,说结束的字符串:

('this', 'that') 

我知道我能得到逗号与。加入(),我怎样才能解决每个项目的报价中最优雅办法?

+3

只需使用'repr':'再版(数组(数组))' – vaultah

+0

,使该正确的答案,但方括号;有没有简单的把它们换成圆形的? (这是一个SQL查询) – cjm2671

+2

奇怪的是,'repr(tuple(array))'给了我很好的圆括号。 – Kevin

回答

3

Like vaultah表示使用repr()它用于计算对象的字符串表示形式。

例如,

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

然后array = repr(tuple(array))

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