python字符串和列表的相互转换实例


本文摘自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如何读取csv文件

Python有哪些需要学习的知识?

Python语法基础详解

Python复数的虚部怎么表达

Python怎么把三位数拆开

Python2.7和3.5有什么区别

Python的数据结构

Python如何求10个数的平均数

Python要用什么软件

Python操作二维数组画图

更多相关阅读请进入《Python》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...