For example, the following loop will execute without any error.
Given:
for i in range(5): print(i)
Expected output:
0 1 2 3 4 Done!
Hint:
Same as the if statement, Python allows us to use an else block along with for loop. for loop can have the else block, which will be executed when the loop terminates normally.
if
for
else
Solution:
for i in range(5): print(i) else: print("Done!")
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Hint:
Same as the
if
statement, Python allows us to use an else block along withfor
loop.for
loop can have theelse
block, which will be executed when the loop terminates normally.Solution:
need an explanation for this answer? contact us directly to get an explanation for this answer