0
>>> 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
  • 112,593
  • 23
  • 157
  • 280
Naaman Smith
  • 23
  • 1
  • 3
  • 1
    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
  • 20,986
  • 7
  • 47
  • 78
Derek
  • 6,859
  • 4
  • 31
  • 53