The range() function defaults to 0 as a starting value.
However, it is possible to specify the starting value by adding a first parameter: range(start, end).
For example:
range(2, 6) # returns the sequence [2, 3, 4, 5]
Looping through numbers:
We can use range() and for to loop through the numbers in some range:
for i in range(2, 6):
print(i)
The output of this code is:
2
3
4
5
Assignment
Let's print all numbers from 3 through 10 using a for loop.
Hint
Look at the examples above if you get stuck.
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
