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 !

 

posted @ 2018-02-14 11:58  竹雨听闲  阅读(18169)  评论(0编辑  收藏  举报