2016-10-20 26 views
-1

我有點新的Python,我想知道如何把一個用戶輸入到一個數組如何把用戶輸入到一個數組

例如:

usersentence = input("Type out the sentence: ") 

我想把用戶輸入到數組中,我很困惑如何做到這一點。我的程序確定了這個詞在句子中的位置,忽略了標點符號以及它是否是上限。

謝謝,如果你幫忙!

+0

要提出的問題的話成陣列? – Saran

+0

'new_array.append(usersentence)'告訴我們你的代碼,否則我們不能幫你。它的所有相關部分。 –

+0

告訴我們你的輸入如何輸入 – LittleQ

回答

0

你可以把你的項目列表中,像這樣:

usersentence = [input("Type out the sentence: ")] 
print(usersentence) 

>>> Type out the sentence: hello world 
>>> ['hello world'] 

如果你想在每個列表項一個字:

usersentence = input("Type out the sentence: ").split() 
print(usersentence) 

>>> Type out the sentence: hello world 
>>> ['hello', 'world']