Computer >> Computer tutorials >  >> Programming >> Python

How do we assign values to variables in a list using a loop in Python?


Python’s built-in list class has append() method. We can get user input and add it to list till user presses Enter key. An infinite while loop contains input() function and append() method

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