I am having trouble understanding a Python for loop. For example, here is some code I\'ve made while I\'m learning:
board = []
for i in range (0,5):
board.ap
Think of it as substitution.
range(0,5)
is [0,1,2,3,4]
. The for-loop goes through each element in the list, naming the element i
.
for i in range(0,5):
# Starts with 0
print i # prints 0
# now goes back, goes through next element in list: 1.
Prints 0,1,2,3,4.
In your example, i is a placeholder. It is used simply just to loop something x amount of times (in this case, five as the length of range(0,5) is 5)
Also, have fun learning python at Codecademy (I recognise the task :p)