1. 程式人生 > >python中的list,字符串轉換

python中的list,字符串轉換

換問題 字符串 編程 googl python google www. ogl copy

在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

python中的list,字符串轉換