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 input怎么用

Python并发之poolexecutor的介绍(附示例)

Python如何生成马赛克画?生成马赛克画的方法(代码详解)

Python安装了怎么用

Python中tuple指什么

Python函数式编程是什么?

Python中yield什么意思

Python中如何优雅的合并两个字典(dict)

Python之变量的学习介绍

Python里lambda是什么

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




打赏

取消

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

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

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

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

评论

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