一:str→list
str1=‘ penny ‘ str2=list(str1) print(str2) str3=‘how are you today‘ str4=str3.split() print(str4) str5=‘www.taobao.com‘ str6=str5.split(‘.‘) print(str6)
运行结果:
[‘ ‘, ‘p‘, ‘e‘, ‘n‘, ‘n‘, ‘y‘, ‘ ‘] [‘how‘, ‘are‘, ‘you‘, ‘today‘] [‘www‘, ‘taobao‘, ‘com‘]
二:list→str
str22="".join(str2) print(str22) str44=" ".join(str4) print(str44) str66=".".join(str6) print(str66)
运行结果:
penny
how are you today
www.taobao.com
原文:https://www.cnblogs.com/pennyxiaoxiantu/p/11413943.html