-9
讓我們說用戶想輸入100個東西;但我不想讓我的腳本擁有100,x = raw_input('')
,是否有這樣做?python想知道用戶輸入
讓我們說用戶想輸入100個東西;但我不想讓我的腳本擁有100,x = raw_input('')
,是否有這樣做?python想知道用戶輸入
使用一個列表和一個while
循環。
data=[]
for x in xrange(100):
data.append(raw_input("Your data: "))
如果你並不需要保存已輸入的數據,擺脫清單和流程中循環這個數據正確的。
注意:'data = [raw_input(「Your data:」)for _ in xrange(100)]'。 –
https://docs.python.org/2/reference/compound_stmts.html#for –
另請參閱http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they對技術進行有效的迴應以確保用戶輸入有效。 –