如何在python中使用input()函数在列表中追加多个输入?

时间:2017-05-07 12:33:15

标签: python list for-loop append

1 个答案:

答案 0 :(得分:0)

myList = []


while True:
  word = input("Enter a Word (Type 'q' to quit): ")
  if word == 'q':
    break
  myList.append(word)

print(myList)

<强> RESULT

Enter a Word (Type 'q' to quit):  cat
Enter a Word (Type 'q' to quit):  dog
Enter a Word (Type 'q' to quit):  rat
Enter a Word (Type 'q' to quit):  q
['cat', 'dog', 'rat']