0
game = [[2, 2, 3],

        [1, 1, 3],

        [0, 0, 3]]

vertical = []

for row in game:

  print(vertical.append(row[2]))  

I try to understand the append function by print it out. The output is kind of confusing to me. Is that because I did not add any value to the vertical variable?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

You should have a look into the documentation of the append() function. In short: It doesn't return a value. This is why you get NULL instead of your wanted 3.

This is what you want to do instead:

game = [[2, 2, 3],

        [1, 1, 3],

        [0, 0, 3]]

vertical = []

for row in game:
    vertical.append(row[2])
    print(vertical)

If you have additional questions, feel free to ask.

Edit: adding the print(vertical) outside of the for loop makes more sense for actual code, inside the for function is however better for debugging.

Baut
  • 59
  • 3