我的字符串是:
wish = "Happy New Year"
输出:
word_list = ['Happy','New','Year']
答案 0 :(得分:3)
>>> wish = "Happy New Year"
>>> wordlist = wish.split()
>>> wordlist
['Happy', 'New', 'Year']
>>>
你可以看到字符串函数split的帮助。
>>> help(''.split)
Help on built-in function split:
split(...)
S.split([sep [,maxsplit]]) -> list of strings
Return a list of the words in the string S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.
>>>
答案 1 :(得分:0)
请参阅字符串的split方法。
"Happy New Year".split()
这会产生你的数组。