-1
>>> alist = [["H"]]
>>> mylist = alist[0].append([2])
>>> print(mylist)
>>>

As you can see it prints nothing. I'm trying to get this as the result.

>>> [["H", [2]]]

Any help?

martineau
  • 119,623
  • 25
  • 170
  • 301
Naaman Smith
  • 41
  • 1
  • 4
  • 2
    It should've printed `None`. Did you actually `print`, or did you just say `mylist`? – user2357112 Jun 30 '17 at 17:23
  • `alist[0].append([2])` actually appends `[2]` to `alist`. It returns `None`. If you check `alist` it should have `['H', [2]]`... – victor Jun 30 '17 at 17:24

1 Answers1

0

.append() actually appends to the existing list, it does not return a new list:

alist = [["H"]]
alist[0].append(2)
print( alist )
Christian Dean
  • 22,138
  • 7
  • 54
  • 87
Derek
  • 7,615
  • 5
  • 33
  • 58