我们如何使用Python中的循环将值分配给列表中的变量?

Python的内置列表类具有append()方法。我们可以获取用户输入并将其添加到列表中,直到用户按下Enter键为止。无限的while循环包含input()函数和append()方法

L=[]
while True:
  item=input("enter new item")
  if item=='':
    break
  L.append(item)
print ("List : ",L)