How this command printed "O"?

print board[2][3]

The example above prints out "O", the element in the 3rd row and 4th column.
How it works?

board[guess_row][guess_col] = "X"
print print_board(board)

Will print at which place in 5x5 grid?


lists indexes are zero indexes based, so a list with a length of 5 would have the following indexes: 0, 1, 2, 3 and 4


I know that but how come print board[2][3] prints the "O" which is the element of the 3rd row and 4th column?

Also when given the input as 2 and 3 it should print the x on the 2nd row and 3rd column. But it prints on some where else.

So how come this works?


i assume 3rd and 4th, then you start counting at one? That perfectly matches with 2 and 3 if you count is zero based (starting counting at zero). So that is why.

if you want to do this, you will have to compensate for the fact that you start counting at one, and the lists start counting at zero. Since you are working in a programming language, the easiest fix is simply to subtract one from the user input to compensate for this difference


Thank's a lot man. Now understood.