3/19 - Lost :( forgot how for, in and range functions work


#1

https://www.codecademy.com/courses/python-beginner-en-4XuFm/0/3?curriculum_id=4f89dab3d788890003000096#

I don't get this...I've pasted in the correct working code from someone else but I don't understand it myself. Specifically, how does "for i in range(5):" work to loop the five O's five times?


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


#2

The loop is a repeater. The "for" loop means that each "thing" (which you assigned as "i") in range(5) (which means that there are 5 spaces that you will do this for, you are using the .append() to put the "O" into those 5 blank spaces. The * 5 means that you are doing that 5 times to make 5 rows.

Hope that helps clarify things a bit.