-5

Suppose a list in Python -> mylist:

mylist = []

I want to now take input from users and update the values afterward in mylist:

input1 = ["xyz","wyh",34]
print mylist
Output: [["xyz","wyh",34]]

input2 = ["yo","hey",657]
print mylist
output: [["xyz","wyh",34],["yo","hey",657]]

append() only works when list has some values already.

pault
  • 41,343
  • 15
  • 107
  • 149

2 Answers2

0

you can use list.append

 mylist.append(["L","M",56])
 (or)
 mylist+[["L","M",56]]
Pyd
  • 6,017
  • 18
  • 52
  • 109
0

I'd advise you take a look through here to see what exactly you need. It sounds like what you want is list.append() however.

mylist = [["X","Y",12], ["A","B",23]]
mylist.append(["L","M",56])
Mark R
  • 337
  • 2
  • 9
  • What if the list value is null, then it won't append. What in such cases? – Devesh Pal Aug 03 '18 at 16:19
  • You should initialize the list at first with mylist = [] if you don't have any initial values. Append will work on any list, even if it's empty – Mark R Aug 03 '18 at 16:34