本文摘自php中文网,作者零下一度,侵删。
1.str >>>list 1 2 3 4 | [python] view plain copy
str 1 = "12345"
list 1 = list(str 1 )
print list 1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 | str2 = "123 sjhid dhi"
list2 = str2.split() #or list2 = str2.split( " " )
print list2
str3 = "www.google.com"
list3 = str3.split( "." )
print list3
[python] view plain copy
输出为:
[python] view plain copy
[ '1' , '2' , '3' , '4' , '5' ]
[ '123' , 'sjhid' , 'dhi' ]
[ 'www' , 'google' , 'com' ]
|
3.list >>>str
1 2 3 4 5 6 7 | [python] view plain copy
str 4 = "" .join(list 3 )
print str 4
str 5 = "." .join(list 3 )
print str 5
str 6 = " " .join(list 3 )
print str 6
|
输出为:
1 2 3 4 | [python] view plain copy
wwwgooglecom
www.google.com
www google com
|
以上就是python字符串和列表的相互转换实例的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python入门教程之列表操作
怎么用Python画圆
数据分析师为什么要学Python
Python中什么叫类
Python如何生成exe文件
Python后端是什么
Python项目如何运行
Python tuple什么意思
Python怎么安装opencv
Python关于tkinter模块中类的三种继承方式示例分享
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python字符串和列表的相互转换实例