07 Lecture Iterative Statements
07 Lecture Iterative Statements
Lecture 07:
Iterative Statements in Python
Output:
1
2
3
4
5
Python code to illustrate for statement with
Range function
Range(start_value,end_value, step)
Range(1,5) 1234
Range(5) 01234
Range(1,10,2) 13579
range(5,1,-1) 5432
Printing Without Newline
# Python code to illustrate for statement with Range function
for value in range(1, 6):
print(value, end=“”)
print('Job is done!’)
Output:
12345
for statement with 'else' clause in Python
• In Python, the else clause can be used with a for a statement.
• The else block is gets executed whenever the for statement is does
not terminated with a break statement.
• But, if the for loop is terminated with break statement then else block
doesn't execute.