int*_*el3 85 python string tuples
我有一个像这样的字符元组:
('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
如何将其转换为字符串,使其如下所示:
'abcdgxre'
iCo*_*dez 139
用途str.join:
>>> tup = ('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')
>>> ''.join(tup)
'abcdgxre'
>>>
>>> help(str.join)
Help on method_descriptor:
join(...)
    S.join(iterable) -> str
    Return a string which is the concatenation of the strings in the
    iterable.  The separator between elements is S.
>>>
Bac*_*ics 24
这是一种使用join的简单方法.
''.join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))
Tru*_*ker 10
这有效:
''.join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))
它会产生:
'abcdgxre'
您还可以使用逗号分隔符来生成:
'a,b,c,d,g,x,r,e'
通过使用:
','.join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))