Python:13.5 Custom Print


#1

Hello Friends, I have a doubt about

https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/5?curriculum_id=4f89dab3d788890003000096.Following is my code


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

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


Although my code works fine, I am confused about the declaration of "row" .How does computer understands what "row" is without us declaring it.


#2

But we do 'define' it, in the for statement. It is the declared iterator variable to take each item in the board list, one at a time and in order. These are lists that are independent of one another. It's a convenience to call it a 'row', but also sensible, since that is what it is on the screen.


#3

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