Python While and For Loops MCQs with Answers

Practice MCQs for While and For Loops

Explore reliable objective questions for While and For Loops tailored for learners. Utilizing these multiple-choice formats ensures thorough preparation and strengthens problem-solving speed for upcoming school assessments.

Access While and For Loops Questions and Solutions

View or download the dedicated While and For Loops MCQ resource below. Practicing these 50 objective questions regularly builds familiarity with standard exam patterns and helps secure higher marks in final evaluations.

Question. What will be the output of the following Python code?
x = ['ab', 'cd']
for i in x:
    i.upper()
print(x)

(a) [‘ab’, ‘cd’]
(b) [‘AB’, ‘CD’]
(c) [None, None]
(d) none of the mentioned
Answer: a
Explanation: The function upper() does not modify a string in place, it returns a new string which isn’t being stored anywhere.

Question. What will be the output of the following Python code?
x = ['ab', 'cd']
for i in x:
    x.append(i.upper())
print(x)

(a) [‘AB’, ‘CD’]
(b) [‘ab’, ‘cd’, ‘AB’, ‘CD’]
(c) [‘ab’, ‘cd’]
(d) none of the mentioned
Answer: d
Explanation: The loop does not terminate as new elements are being added to the list in each iteration.

Question. What will be the output of the following Python code?
i = 1
while True:
    if i%3 == 0:
        break
    print(i)

    i + = 1

(a) 1 2
(b) 1 2 3
(c) error
(d) none of the mentioned
Answer: c
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.

Question. What will be the output of the following Python code?
i = 1
while True:
    if i%0O7 == 0:
        break
    print(i)
    i += 1

(a) 1 2 3 4 5 6
(b) 1 2 3 4 5 6 7
(c) error
(d) none of the mentioned
Answer: a
Explanation: Control exits the loop when i becomes 7.

Question. What will be the output of the following Python code?
i = 5
while True:
    if i%0O11 == 0:
        break
    print(i)
    i += 1

(a) 5 6 7 8 9 10
(b) 5 6 7 8
(c) 5 6
(d) error
Answer: b
Explanation: 0O11 is an octal number.

Question. What will be the output of the following Python code?
i = 5
while True:
    if i%0O9 == 0:
        break
    print(i)
    i += 1

(a) 5 6 7 8
(b) 5 6 7 8 9
(c) 5 6 7 8 9 10 11 12 13 14 15 ….
(d) error
Answer: d
Explanation: 9 isn’t allowed in an octal number.

Question. What will be the output of the following Python code?
i = 1
while True:
    if i%2 == 0:
        break
    print(i)
    i += 2

(a) 1
(b) 1 2
(c) 1 2 3 4 5 6 …
(d) 1 3 5 7 9 11 …
Answer: d
Explanation: The loop does not terminate since i is never an even number.

Question. What will be the output of the following Python code?
i = 2
while True:
    if i%3 == 0:
        break
    print(i)
    i += 2

(a) 2 4 6 8 10 …
(b) 2 4
(c) 2 3
(d) error
Answer: b
Explanation: The numbers 2 and 4 are printed. The next value of i is 6 which is divisible by 3 and hence control exits the loop.

Question. What will be the output of the following Python code?
i = 1
while False:
    if i%2 == 0:
        break
    print(i)
    i += 2

(a) 1
(b) 1 3 5 7 …
(c) 1 2 3 4 …
(d) none of the mentioned
Answer: d
Explanation: Control does not enter the loop because of False.

Question. What will be the output of the following Python code?
True = False
while True:
    print(True)
    break

(a) True
(b) False
(c) None
(d) none of the mentioned
Answer: d
Explanation: SyntaxError, True is a keyword and it’s value cannot be changed.

Question. What will be the output of the following Python code?
i = 0
while i < 5:
    print(i)
    i += 1
    if i == 3:
        break
else:
    print(0)

(a) 0 1 2 0
(b) 0 1 2
(c) error
(d) none of the mentioned
Answer: b
Explanation: The else part is not executed if control breaks out of the loop.

Question. What will be the output of the following Python code?
i = 0
while i < 3:
    print(i)
    i += 1
else:
    print(0)

(a) 0 1 2 3 0
(b) 0 1 2 0
(c) 0 1 2
(d) error
Answer: b
Explanation: The else part is executed when the condition in the while statement is false.

Question. What will be the output of the following Python code?
x = "abcdef"
while i in x:
    print(i, end=" ")

(a) a b c d e f
(b) abcdef
(c) i i i i i i …
(d) error
Answer: d
Explanation: NameError, i is not defined.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "i"
while i in x:
    print(i, end=" ")

(a) no output
(b) i i i i i i …
(c) a b c d e f
(d) abcdef
Answer: a
Explanation: “i” is not in “abcdef”.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
    print(i, end = " ")

(a) no output
(b) i i i i i i …
(c) a a a a a a …
(d) a b c d e f
Answer: c
Explanation: As the value of i or x isn’t changing, the condition will always evaluate to True.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
    print('i', end = " ")

(a) no output
(b) i i i i i i …
(c) a a a a a a …
(d) a b c d e f
Answer: b
Explanation: As the value of i or x isn’t changing, the condition will always evaluate to True.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
    x = x[:-1]
    print(i, end = " ")

(a) i i i i i i
(b) a a a a a a
(c) a a a a a
(d) none of the mentioned
Answer: b
Explanation: The string x is being shortened by one character in each iteration.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x[:-1]:
    print(i, end = " ")

(a) a a a a a
(b) a a a a a a
(c) a a a a a a …
(d) a
Answer: c
Explanation: String x is not being altered and i is in x[:-1].

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x:
    x = x[1:]
    print(i, end = " ")

(a) a a a a a a
(b) a
(c) no output
(d) error
Answer: b
Explanation: The string x is being shortened by one character in each iteration.

Question. What will be the output of the following Python code?
x = "abcdef"
i = "a"
while i in x[1:]:
    print(i, end = " ")

(a) a a a a a a
(b) a
(c) no output
(d) error
Answer: c
Explanation: i is not in x[1:].

Question. What will be the output of the following Python code?
x = 'abcd'
for i in x:
    print(i)
    x.upper()

(a) a B C D
(b) a b c d
(c) A B C D
(d) error
Answer: b
Explanation: Changes do not happen in-place, rather a new instance of the string is returned.

Question. What will be the output of the following Python code?
x = 'abcd'
for i in x:
    print(i.upper())

(a) a b c d
(b) A B C D
(c) a B C D
(d) error
Answer: b
Explanation: The instance of the string returned by upper() is being printed.

Question. What will be the output of the following Python code?
x = 'abcd'
for i in range(x):
    print(i)

(a) a b c d
(b) 0 1 2 3
(c) error
(d) none of the mentioned
Answer: c
Explanation: range(str) is not allowed.

Question. What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
    print(i)

(a) a b c d
(b) 0 1 2 3
(c) error
(d) 1 2 3 4
Answer: b
Explanation: i takes values 0, 1, 2 and 3.

Question. What will be the output of the following Python code?
x = 'abcd'
for i in range(len(x)):
    print(i.upper())

(a) a b c d
(b) 0 1 2 3
(c) error
(d) 1 2 3 4
Answer: c
Explanation: Objects of type int have no attribute upper().

Question. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
    i.upper()
print (x)

(a) a b c d
(b) 0 1 2 3
(c) error
(d) none of the mentioned
Answer: c
Explanation: Objects of type int have no attribute upper().

Question. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
    x[i].upper()
print (x)

(a) abcd
(b) ABCD
(c) error
(d) none of the mentioned
Answer: a
Explanation: Changes do not happen in-place, rather a new instance of the string is returned.

Question. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
    i[x].upper()
print (x)

(a) abcd
(b) ABCD
(c) error
(d) none of the mentioned
Answer: c
Explanation: Objects of type int aren’t subscriptable. However, if the statement was x[i], an error would not have been thrown.

Question. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
    x = 'a'
    print(x)

(a) a
(b) abcd abcd abcd
(c) a a a a
(d) none of the mentioned
Answer: c
Explanation: range() is computed only at the time of entering the loop.

Question. What will be the output of the following Python code snippet?
x = 'abcd'
for i in range(len(x)):
    print(x)
    x = 'a'

(a) a
(b) abcd abcd abcd abcd
(c) a a a a
(d) none of the mentioned
Answer: d
Explanation: abcd a a a is the output as x is modified only after ‘abcd’ has been printed once.

Question. What will be the output of the following Python code?
x = 123
for i in x:
    print(i)

(a) 1 2 3
(b) 123
(c) error
(d) none of the mentioned
Answer: (c)
Explanation: Objects of type int are not iterable.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for i in d:
    print(i)

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (a)
Explanation: Loops over the keys of the dictionary.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d:
    print(x, y)

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (d)
Explanation: Error, objects of type int aren’t iterable.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x, y in d.items():
    print(x, y)

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (c)
Explanation: Loops over key, value pairs.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.keys():
    print(d[x])

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (b)
Explanation: Loops over the keys and prints the values.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
    print(x)

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (b)
Explanation: Loops over the values.

Question. What will be the output of the following Python code?
d = {0: 'a', 1: 'b', 2: 'c'}
for x in d.values():
    print(d[x])

(a) 0 1 2
(b) a b c
(c) 0 a 1 b 2 c
(d) none of the mentioned
Answer: (d)
Explanation: Causes a KeyError.

Question. What will be the output of the following Python code?
d = {0, 1, 2}
for x in d.values():
    print(x)

(a) 0 1 2
(b) None None None
(c) error
(d) none of the mentioned
Answer: (c)
Explanation: Objects of type set have no attribute values.

Question. What will be the output of the following Python code?
d = {0, 1, 2}
for x in d:
    print(x)

(a) 0 1 2
(b) {0, 1, 2} {0, 1, 2} {0, 1, 2}
(c) error
(d) none of the mentioned
Answer: (a)
Explanation: Loops over the elements of the set and prints them.

Question. What will be the output of the following Python code?
d = {0, 1, 2}
for x in d:
    print(d.add(x))

(a) 0 1 2
(b) 0 1 2 0 1 2 0 1 2 …
(c) None None None
(d) None of the mentioned
Answer: (c)
Explanation: Variable x takes the values 0, 1 and 2. set.add() returns None which is printed.

Question. What will be the output of the following Python code?
for i in range(0):
    print(i)

(a) 0
(b) no output
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: range(0) is empty.

Question. What will be the output of the following Python code?
for i in range(2.0):
    print(i)

(a) 0.0 1.0
(b) 0 1
(c) error
(d) none of the mentioned
Answer: (c)
Explanation: Object of type float cannot be interpreted as an integer.

Question. What will be the output of the following Python code?
for i in range(int(2.0)):
    print(i)

(a) 0.0 1.0
(b) 0 1
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: range(int(2.0)) is the same as range(2).

Question. What will be the output of the following Python code?
for i in range(float('inf')):
    print (i)

(a) 0.0 0.1 0.2 0.3 …
(b) 0 1 2 3 …
(c) 0.0 1.0 2.0 3.0 …
(d) none of the mentioned
Answer: (d)
Explanation: Error, objects of type float cannot be interpreted as an integer.

Question. What will be the output of the following Python code?
for i in range(int(float('inf'))):
    print (i)

(a) 0.0 0.1 0.2 0.3 …
(b) 0 1 2 3 …
(c) 0.0 1.0 2.0 3.0 …
(d) none of the mentioned
Answer: (d)
Explanation: OverflowError, cannot convert float infinity to integer.

Question. What will be the output of the following Python code snippet?
for i in [1, 2, 3, 4][::-1]:
    print (i)

(a) 1 2 3 4
(b) 4 3 2 1
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: [::-1] reverses the list.

Question. What will be the output of the following Python code snippet?
for i in ''.join(reversed(list('abcd'))):
    print (i)

(a) a b c d
(b) d c b a
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: ‘ ‘.join(reversed(list(‘abcd’))) reverses a string.

Question. What will be the output of the following Python code snippet?
for i in 'abcd'[::-1]:
    print (i)

(a) a b c d
(b) d c b a
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: [::-1] reverses the string.

Question. What will be the output of the following Python code snippet?
for i in '':
    print (i)

(a) None
(b) (nothing is printed)
(c) error
(d) none of the mentioned
Answer: (b)
Explanation: The string does not have any character to loop over.

Question. What will be the output of the following Python code snippet?
x = 2
for i in range(x):
    x += 1
    print (x)

(a) 0 1 2 3 4 …
(b) 0 1
(c) 3 4
(d) 0 1 2 3
Answer: (c)
Explanation: Variable x is incremented and printed twice.

Question. What will be the output of the following Python code snippet?
x = 2
for i in range(x):
    x -= 2
    print (x)

(a) 0 1 2 3 4 …
(b) 0 -2
(c) 0
(d) error
Answer: (b)
Explanation: The loop is entered twice.

Question. What will be the output of the following Python code?
for i in range(10):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

(a) 0 1 2 3 4 Here
(b) 0 1 2 3 4 5 Here
(c) 0 1 2 3 4
(d) 1 2 3 4 5
Answer: (c)
Explanation: The else part is executed if control doesn’t break out of the loop.

Question. What will be the output of the following Python code?
for i in range(5):
    if i == 5:
        break
    else:
        print(i)
else:
    print("Here")

(a) 0 1 2 3 4 Here
(b) 0 1 2 3 4 5 Here
(c) 0 1 2 3 4
(d) 1 2 3 4 5
Answer: (a)
Explanation: The else part is executed if control doesn’t break out of the loop.

Question. What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
    print(i)

(a) 0 1 2
(b) error
(c) 0 1 2 0 1 2
(d) none of the mentioned
Answer: (a)
Explanation: The first statement creates a generator object.

Question. What will be the output of the following Python code?
x = (i for i in range(3))
for i in x:
    print(i)
for i in x:
    print(i)

(a) 0 1 2
(b) error
(c) 0 1 2 0 1 2
(d) none of the mentioned
Answer: (a)
Explanation: We can loop over a generator object only once.

Question. What will be the output of the following Python code?
string = "my name is x"
for i in string:
    print (i, end=", ")

(a) m, y, , n, a, m, e, , i, s, , x,
(b) m, y, , n, a, m, e, , i, s, , x
(c) my, name, is, x,
(d) error
Answer: (a)
Explanation: Variable i takes the value of one character at a time.

Question. What will be the output of the following Python code?
string = "my name is x"
for i in string.split():
    print (i, end=", ")

(a) m, y, , n, a, m, e, , i, s, , x,
(b) m, y, , n, a, m, e, , i, s, , x
(c) my, name, is, x,
(d) error
Answer: (c)
Explanation: Variable i takes the value of one word at a time.

Question. What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
for a[-1] in a:
    print(a[-1])

(a) 0 1 2 3
(b) 0 1 2 2
(c) 3 3 3 3
(d) error
Answer: (b)
Explanation: The value of a[-1] changes in each iteration.

Question. What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
for a[0] in a:
    print(a[0])

(a) 0 1 2 3
(b) 0 1 2 2
(c) 3 3 3 3
(d) error
Answer: (a)
Explanation: The value of a[0] changes in each iteration. Since the first value that it takes is itself, there is no visible error in the current example.

Question. What will be the output of the following Python code snippet?
a = [0, 1, 2, 3]
i = -2
for i not in a:
    print(i)
    i += 1

(a) -2 -1
(b) 0
(c) error
(d) none of the mentioned
Answer: (c)
Explanation: SyntaxError, not in isn’t allowed in for loops.

Question. What will be the output of the following Python code snippet?
string = "my name is x"
for i in ' '.join(string.split()):
    print (i, end=", ")

(a) m, y, , n, a, m, e, , i, s, , x,
(b) m, y, , n, a, m, e, , i, s, , x
(c) my, name, is, x,
(d) error
Answer: (a)
Explanation: Variable i takes the value of one character at a time.

Multiple Choice Questions (MCQs) for While and For Loops

Download Multiple Choice Questions: While and For Loops ( )

Explore reliable practice questions for While and For Loops tailored for learners. Use these multiple-choice formats to evaluate preparedness and strengthen problem-solving skills.

Concept Clarification for While and For Loops

Cross-reference your completed choices with comprehensive NCERT solutions for to ensure absolute clarity across all sub-topics in this chapter.

Additional Study Resources for

Explore our broader library of printable assignments, chapter notes, and mock tests designed to support continuous revision and secure higher marks in NCERT assessments.

FAQs

Where can I access latest Python While and For Loops MCQs with Answers?

You can get most exhaustive Python While and For Loops MCQs with Answers for free on StudiesToday.com. These MCQs for are updated for the 2026-27 academic session as per examination standards.

Are Assertion-Reasoning and Case-Study MCQs included in the [current-page:node:field_subject] [current-page:node:field_class] material?

Yes, our Python While and For Loops MCQs with Answers include the latest type of questions, such as Assertion-Reasoning and Case-based MCQs. 50% of the paper is now competency-based.

How do practicing [current-page:node:field_subject] MCQs help in scoring full marks in [current-page:node:field_class] exams?

By solving our Python While and For Loops MCQs with Answers, students can improve their accuracy and speed which is important as objective questions provide a chance to secure 100% marks in the .

Do you provide answers and explanations for Python While and For Loops MCQs with Answers?

Yes, MCQs for have answer key and brief explanations to help students understand logic behind the correct option as its important for 2026 competency-focused exams.

Can I practice these [current-page:node:field_subject] [current-page:node:field_class] MCQs online?

Yes, you can also access online interactive tests for Python While and For Loops MCQs with Answers on StudiesToday.com as they provide instant answers and score to help you track your progress in .