Lesson 12 of 34
for Loops and range()
9 min 25 XP
Don't write the same line 100 times! A for loop repeats work as many times as you say. range(5) gives 0, 1, 2, 3, 4.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.range(start, stop, step) starts at start and stops before stop. step is how much to add each time.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.A for loop can also go through each character of a string.
Example: edit me and press Run
Output Loading Python (first time takes a few seconds)
Press Run to see the result here.range(1, 11) means 1 to 10. The last number (11) is not included!