19/5 Custom Print (need explanation)


board = [] for i in range(5): __board.append(['O'] * 5) def print_board(board): __for row in board: ____ print row print print_board(board)
why does
def print_board(board): __for row in board: ____ print row
prints everything in new line?


Every time you print after a different ‘print’ it will go down to the next line:

print “Hello”
print “World!”

if this code is run, on the console you will see:


In the for loop you have created (for row in board…), the ‘print’ command is repeated several times, here is part of the loop broken down:

hope this helps. sorry if it doesn’t


Thank you!


Did it help you???


I got it now :smiley:
thx man
(it definitely help my out)


You’re welcome :grinning:

board = []

for x in range(0, 5):
    x = 'O'
def print_board(board):
    for O in range(0, len(board)):
        print board[O]


This one works for me. Try this this out.