What is the output of the following Python code snippet?
for i in range(2):
print(i, end=' ')
else:
print('done')
print(i, end=' ')
else:
print('done')
Correct answer
C. 0 1 done
5 views
C. 0 1 done
5 views
The loop's else block runs when the loop finishes without hitting break.
Asked in: Python Interview Control Flow
https://docs.python.org/3/tutorial/controlflow.htmlNot sure why the answer is C? Ask here and get an explanation.