字符串(str)转列表(list)
转换方法:str.split()
str = 'zhu gao chao' print(str.split(' ')) # 用split进行转换 str——>list 执行结果: ['zhu', 'gao', 'chao'] Process finished with exit code 0
列表(list)转字符串(str)
转换方法: str.join(list)
lis = ['zhu', 'gao', 'chao'] str = ''.join(lis) # 无缝拼接 print(str) #执行结果: zhugaochao Process finished with exit code 0 lis = ['zhu', 'gao', 'chao'] str = ','.join(lis) # 用 , 拼接 print(str) #执行结果: zhu,gao,chao Process finished with exit code 0
待更新……