小编典典

Python将元组转换为字符串

python

我有一个这样的字符元组:

('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')

我如何将其转换为字符串,使其类似于:

'abcdgxre'

阅读 241

收藏
2020-12-20

共1个答案

小编典典

用途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.

>>>
2020-12-20