数组(list)转换为字符串(str)
当一个数组中每一个元素的类型都是str类型的时候,可以通过一下方式,将其转换为一个字符串。
>>> a = ['1','2','3','4']
>>> ''.join(a)
'1234'
>>> a = ['1','2','3','4']
>>> type(a)
<class 'list'>
>>> b = ''.join(a)
>>> b
'1234'
>>> type(b)
<class 'str'>
>>>
当一个数组中每一个元素的类型都是str类型的时候,可以通过一下方式,将其转换为一个字符串。
>>> a = ['1','2','3','4']
>>> ''.join(a)
'1234'
>>> a = ['1','2','3','4']
>>> type(a)
<class 'list'>
>>> b = ''.join(a)
>>> b
'1234'
>>> type(b)
<class 'str'>
>>>
本文标题:Python字符串处理经验总结
本文链接:https://www.haomeiwen.com/subject/hpktkftx.html
网友评论