Question 1
What is the purpose of a for loop in Python?
To define a function
To iterate over a sequence or iterable
To create a conditional statement
To perform arithmetic operations
Question 2
How is the range function typically used in a for loop?
range(start, end)
range(end)
range(start, end, step)
range(step)
Question 3
In a for loop, how can you access both the index and the value of each element in a list?
Using a while loop
Using the enumerate function
Using the index method
Using the iter function
Question 4
What will the following code output?
for i in range(3):
print(i, end =' ')
0 1 2
1 2 3
0 1 2 3
1 2 3 4
Question 5
How can you iterate over the elements of a list in reverse order using a for loop?
Using the reversed function
Using the reverse method
Using a negative step in the range function
Python doesn't support iterating in reverse order
Question 6
What is the purpose of the continue keyword in a for loop?
To exit the loop
To skip the remaining code and move to the next iteration
To restart the loop from the beginning
To print the current iteration and continue
Question 7
What is the difference between a for loop and a while loop?
For loops iterate over sequences, while while loops run based on a condition.
For loops are better than while loop.
They are not interchangeable.
For loop is faster than while loop.
Question 8
What is the purpose of the pass statement in a for loop?
To terminate the loop
To create an infinite loop
To skip the current iteration and move to the next
To do nothing and continue to the next iteration
Question 9
How can you iterate over the keys and values of a dictionary using a for loop?
for key, value in dictionary.items():
for key in dictionary.keys():
for key in dictionary:
for value in dictionary.values():
Question 10
What is the significance of the break and else combination in a for loop?
Executes else only if loop wasn't exited by break.
It is a syntax error; break and else cannot be used together.
It skips the current iteration.
It restarts the loop.
There are 24 questions to complete.