Battleship - Custom Print


I am working on the mentioned section and found a YouTube video to show me the answer, but there is not a lot of technical explanation. My code is the following and it was accepted for this lesson:

board = []

for i in range(0, 5):
    board.append(["O"] * 5)

def print_board(board):
    for i in board:
        print i

Why do I have to use "print i", what am I telling python to do with that command? I apologize if this is a basic question, but I want to know how the code would sound, in my head, if I was speaking the directions.



board is a multi-dimensional list, by looping over it, you get access to the inner lists, which you print (i)


Stetim94, the concept of inner lists is not clear to me. Can you further explain inner lists? I am looking at the code as for i in board and how does that code dictate the format of the output?

I appreciate your assistance.


well this a normal list:


its 1 dimensional. but we can also nest a list inside a list:


which is 2 dimensional. Just like your board. an outer list (in case of your board, that are the columns) and inner lists (your rows)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.