首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python 字符串(str)和列表(list)的互相转换

python 字符串(str)和列表(list)的互相转换

作者头像
双面人
发布2019-04-10 16:16:07
3.5K0
发布2019-04-10 16:16:07
举报
文章被收录于专栏:热爱IT热爱IT

1.str >>>list 

  1. str1 = "12345"
  2. list1 = list(str1)
  3. print list1
  4. str2 = "123 sjhid dhi"
  5. list2 = str2.split() #or list2 = str2.split(" ")
  6. print list2
  7. str3 = "www.google.com"
  8. list3 = str3.split(".")
  9. print list3
输出为:
  1. ['1', '2', '3', '4', '5']
  2. ['123', 'sjhid', 'dhi']
  3. ['www', 'google', 'com']

3.list >>>str

  1. str4 = "".join(list3)
  2. print str4
  3. str5 = ".".join(list3)
  4. print str5
  5. str6 = " ".join(list3)
  6. print str6

输出为:

  1. wwwgooglecom
  2. www.google.com
  3. www google com

参考链接:

http://blog.csdn.net/cnmcsdn456/article/details/27830671

http://piziyin.blog.51cto.com/2391349/568426

(adsbygoogle = window.adsbygoogle || []).push({});

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/09/08 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档