Python将元组转换为字符串 [英] Python convert tuple to string

查看:71
本文介绍了Python将元组转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

'abcdgxre'

解决方案

使用 str.join:

<预><代码>>>>tup = ('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e')>>>''.join(tup)'abcdgxre'>>>>>>帮助(str.join)关于 method_descriptor 的帮助:加入(...)S.join(iterable) ->字符串返回一个字符串,它是字符串中字符串的串联可迭代的.元素之间的分隔符是 S.>>>

I have a tuple of characters like such:

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

How do I convert it to a string so that it is like:

'abcdgxre'

解决方案

Use 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.

>>>

这篇关于Python将元组转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆