在Python的编程中,经常会涉及到字符串与list之间的转换问题,下面就将两者之间的转换做一个梳理。
1、list转换成字符串
命令:list()
例子:
2、字符串转换成list
命令:"".join(list)
其中,引号中是字符之间的分割符,如“,”,“;”,“\t”等等
[python] view plain copy
['1', '2', '3', '4', '5']
['123', 'sjhid', 'dhi']
['www', 'google', 'com']
3.list >>>str
[python] view plain copy
str4 = "".join(list3)
print str4
str5 = ".".join(list3)
print str5
str6 = " ".join(list3)
print str6
输出为:
[python] view plain copy
wwwgooglecom
www.google.com
www google com
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦