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

PythonServer Side ProgrammingProgramming

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)
raja
Published on 02-Jan-2018 19:02:14
Advertisements