KnowledgeBoat Logo

Computer Science

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

Python Control Flow

2 Likes

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

Answered By

1 Like


Related Questions