For Loop Range in Python

Level 227 keystrokes

This loops through numbers 0 to 4 and prints each one. range(5) generates a sequence of 5 numbers starting from 0.

Python code

# for is a loop that repeats code for each item in a sequence
# range(5) creates a sequence of numbers: 0, 1, 2, 3, 4
# The variable i takes each value in turn
1for i in range(5):
# The indented code runs once for each value of i
# print(i) displays the current value of i
2 print(i)

Output

0
1
2
3
4
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • (× 2
  • )× 2
  • :× 1

More Python examples at level 2

← Python typing practice