将字符列表转换为字符串 [英] Convert a list of characters into a string

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

问题描述

如果我有一个字符列表:

a = ['a','b','c','d']

如何将其转换为单个字符串?

a = 'abcd'

解决方案

使用空字符串的 join 方法将所有字符串与中间的空字符串连接在一起,如下所示:

<预><代码>>>>a = ['a', 'b', 'c', 'd']>>>''.join(a)'A B C D'

If I have a list of chars:

a = ['a','b','c','d']

How do I convert it into a single string?

a = 'abcd'

解决方案

Use the join method of the empty string to join all of the strings together with the empty string in between, like so:

>>> a = ['a', 'b', 'c', 'd']
>>> ''.join(a)
'abcd'

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

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