CBSE Class 12 Computer Science Question 37 of 120

Review of Python Basics — Question 11

Back to all questions
11
Question

Question 11

What is the output of the following ?

x = 123
for i in x:
    print(i)
  1. 1 2 3
  2. 123
  3. Error
  4. Infinite loop
Answer

Error

Reason — The output of the code will be an error because we cannot directly iterate over an integer object in Python using a for loop. The for loop in Python iterates over iterable objects such as lists, tuples, strings, or dictionaries, but not individual integers