Python From Beginner to Advanced

0% completed

Previous
Next
Quiz
Which Python keyword is used to terminate a loop prematurely?
A
pass
B
exit
C
break
D
return
What will the following code output?
for i in range(5):
    if i == 3:
        break
    print(i)
A
0, 1, 2
B
0, 1, 2, 3
C
0, 1, 2, 3, 4
D
1, 2, 3
Which type of loop is used to iterate over a sequence (such as a list, tuple, dictionary, or string)?
A
while
B
for
C
do-while
D
Python does not have repeat-until loops.
What does the else block in a Python loop execute?
A
Before the loop starts.
B
Immediately after the loop ends and if the loop did not complete (was broken).
C
After the loop completes normally (was not broken by break).
D
Never executes.
What is the output of this loop?
x = 5
while x > 0:
    x -= 1
    if x == 2:
        continue
    print(x)
A
4, 3, 2, 1, 0
B
4, 3, 1, 0
C
4, 3, 2, 1
D
4, 3, 1
In Python, what keyword is used to skip the current iteration of a loop?
A
pass
B
break
C
exit
D
continue

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next