str >>>list
str1 = "12345"
list1 = list(str1)
print list1
str2 = "123 sjhid dhi"
list2 = str2.split() #or list2 = str2.split(" ")
print list2
str3 = "www.google.com"
list3 = str3.split(".")
print list3
输出结果:
['1', '2', '3', '4', '5']
['123', 'sjhid', 'dhi']
['www', 'google', 'com']list >>>str
str4 = "".join(list3)
print str4
str5 = ".".join(list3)
print str5
str6 = " ".join(list3)
print str6输出结果:
wwwgooglecom
www.google.com
www google com转载于:https://blog.youkuaiyun.com/roytao2/article/details/53433373
本文介绍了Python中字符串转换为列表及反向操作的方法,演示了如何使用split()和join()函数进行字符串的拆分与合并,适用于初学者掌握基本的字符串处理技能。
4万+

被折叠的 条评论
为什么被折叠?



