ITPub博客

首页 > IT职业 > IT图书 > python中的list,字符串转换

python中的list,字符串转换

IT图书 作者:samrain 时间:2021-09-09 09:21:40 0 删除 编辑

在Python的编程中,经常会涉及到字符串与list之间的转换问题,下面就将两者之间的转换做一个梳理。
1、list转换成字符串

命令:list()

例子:

2、字符串转换成list
命令:"".join(list)

其中,引号中是字符之间的分割符,如“,”,“;”,“t”等等

[python] view plain copy
['1', '2', '3', '4', '5']  
['123', 'sjhid', 'dhi']  
['www', 'google', 'com']  
3.list >>>str
[python] view plain copy
str4 = "".join(list3)  
print str4  
str5 = ".".join(list3)  
print str5  
str6 = " ".join(list3)  
print str6

输出为:
[python] view plain copy
wwwgooglecom  
 
www google com

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1386/viewspace-2802631/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    108
  • 访问量
    766