python字符串与列表的相互转换

学习内容:

1.字符串转列表

2.列表转字符串

1. 字符串转列表

s ='hello python !'
li = s.split(' ') #注意:引号内有空格
print (li)
输出:
['hello', 'python', '!']

2. 列表转字符串

li = ['hello', 'python', '!']
s = ' '.join(li) #注意:引号内有空格
print(s)

输出:
hello python !

 

原文地址:https://www.cnblogs.com/hokky/p/8440961.html