插件窝 干货文章 python字符串与列表的相互转换

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

python 字符串 列表 422    来源:插件窝    2021-04-20

1. 字符串转列表

str1 = "hi hello world"
print(str1.split(" "))
输出:
['hi', 'hello', 'world']

 


2. 列表转字符串

l = ["hi","hello","world"]
print(" ".join(l))
输出:
hi hello world