本文摘自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 input怎么用
Python并发之poolexecutor的介绍(附示例)
Python如何生成马赛克画?生成马赛克画的方法(代码详解)
Python安装了怎么用
Python中tuple指什么
Python函数式编程是什么?
Python中yield什么意思
Python中如何优雅的合并两个字典(dict)
Python之变量的学习介绍
Python里lambda是什么
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python字符串和列表的相互转换实例