python字符串以空格分割
2023-11-19 23:53:31
可以使用split()方法将字符串以空格分割成列表。例如:
s = "Python字符串以空格分割"
result = s.split()
print(result)
输出结果为:
['Python字符串以空格分割']
如果想要将多个单词以空格分割开,可以在字符串中加入空格。例如:
s = "Python 字符串 以 空格 分割"
result = s.split()
print(result)
输出结果为:
['Python', '字符串', '以', '空格', '分割']