2016-01-01 14 views

回答

0

見字符串分割方法。

"Happy New Year".split() 

這會產生你的數組。

+0

我覺得自己像一個白癡但非常感謝 – Samin

+0

不要對自己如此刻苦。 :)我們都去過那裏。 :) – urosjarc

2
>>> 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. 

>>> 
相關問題