本文摘自php中文网,作者零下一度,侵删。
1.str >>>list 1 2 3 4 | [python] view plain copy
str1 = "12345"
list1 = list(str1)
print list1
|
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
str4 = "".join(list3)
print str4
str5 = ".".join(list3)
print str5
str6 = " ".join(list3)
print str6
|
输出为:
1 2 3 4 | [python] view plain copy
wwwgooglecom
www.google.com
www google com
|
以上就是python字符串和列表的相互转换实例的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python怎么读取excel
Python中len()的用法
哪个手机软件有Python题库
Python中count函数的用法详解
实例详解Python如何轻松实现动态进度条
mac系统可以学Python吗
Python怎么运行
Python数据分析师需要学什么
Python中x的平方怎么写
Python爬虫获取图片并下载保存至本地
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python字符串和列表的相互转换实例