FOR LOOP
A
while
loop is perfect to use when we don't know how many times we want the loop to repeat. If we have an idea of how many times we want the loop to repeat, we can use a
for
loop to loop code in exactly the same way the while
loop did. EXAMPLE :
for counter in range(10):
print(counter)
RANGE
The
range
function creates a list of numbers in the range you create. If you only give it one number, it will start at 0
and move to a state where the final number is one less than the number in the brackets. In this case, the final number would be 9
. EXAMPLE :
total = 0
for number in range(100) :
total += number
print(total)
Comments
Post a Comment