Print board[2][3]


#1

What does

print board[2][3]

mean. What does [2] and [3] mean respectively.


#2

they are index numbers of the list you are accessing


#3

So for

board[2][3]

it refers to index 2 of board and index 3 of board. I thought it was the row number and column number of the board in

Battleship!
Danger, Will Robinson!!


#4

You can imagine it as a 2D matrix (in this case; N square brackets N dimensional matrix). First square brackets are rows in the matrix, second brackets are columns.


#5

If it is the row number and column number, why does

board[2][3]

refer to the 3rd row and 4th column.


#6

because first index is always 0


#7

no, you have a multi dimensional array:

board = [[1,2,3],[4,5,6][7,8,9]]

so board[1][1] would be 5, counting starts from zero, so 1 is array 4,5,6, then the second one is the second item in that array (5)

Because counting starts from zero


#8

Oh, thank you. It's indexing the outer list and indexing a inner list to get a certain item within the two lists. Now it makes sense. Thank you. Also, what is a multi dimensional array?


#9

arrays are called list in pythons, can be confusing working multiply languages. In that case they are nested lists (list nested inside a list)


#10

Thank you very much.