## 将字符列表转换为字符串怎么弄？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (10)
• 关注 (0)
• 查看 (136)

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

`a = 'abcd'`

### 10 个回答

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

```g = ['a', 'b', 'c', 'd']
f=''
for i in range(0,len(g)):
f=f+g[i]
print f```

```    arr = [3, 30, 34, 5, 9]
''.join(map(str,arr))

>> 3303459```

```>>> from operator import concat
>>> a = ['a', 'b', 'c', 'd']
>>> reduce(concat, a)
'abcd'```

`>>> from functools import reduce`

```h = ['a','b','c','d','e','f']
print ''.join(h)```

```import operator
h=['a','b','c','d']

reduce函数也起作用。

```import operator
h=['a','b','c','d']
'abcd'```

```h = ['a','b','c','d','e','f']
g = ''
for f in h:
g = g + f

>>> g
'abcdef'```

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

try:
b = ''.join(a)

except AttributeError:
import string
b = string.join(a, '')```

`b`将是`'abcd'`...

```>> from array import array
>> a = ['a','b','c','d']
>> array('B', map(ord,a)).tostring()
'abcd'```

```>>> ['a', 'b', 'c'].join('')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'list' object has no attribute 'join'```

```# this is the Python way
"".join(['a','b','c','d'])```