python / beginner
Snippet
Counting with range()
The range function generates a sequence of numbers, which is commonly used to run a loop a specific number of times.
snippet.py
1
2
for i in range(3):print("Repeat:", i)
Breakdown
1
for i in range(3):
Starts a loop that will iterate three times (for 0, 1, and 2).
2
print("Repeat:", i)
Prints the current iteration number in each step.