Page 137 - Touchpad_Plus_V3.2_Class 8
P. 137
range(start, stop): Generates a set of whole numbers starting from ‘start’ to ‘stop–1’.
Example: range(3, 9) is equivalent to [3, 4, 5, 6, 7, 8].
range(start, stop, step_size): By default, the value of the step_size = 1 and numbers generated
with a difference of 1. However, we can generate numbers by specifying the value of step_size
according to our requirement.
Example: range(1, 14, 2) is equivalent to [1, 3, 5, 7, 9,11,13].
Program 1: To print whole numbers from 0 to 7 using only stop value.
Program1.py
File Edit Format Run Options Window Help
for i in range (8):
print(i)
You will get the following output:
Output
0
1
2
3
4
5
6
7
Program 2: To print a pattern using for loop.
*
**
***
**** Output
*****
****** *
******* **
******** ***
********* ****
Program2.py *****
File Edit Format Run Options Window Help ******
*******
#Program to create a pattern using for loop ********
for a in range(1,10): *********
print('*'*a)
Loops in Python 135

