KnowledgeBoat Logo

Computer Science

Write the output of the following:

for i in '123':
    print("CPU", i)

Python

Python Control Flow

3 Likes

Answer

CPU 1
CPU 2
CPU 3

Working

The for loop iterates over each character in the string '123' using the in operator, and during each iteration, the variable i takes on the value of each character in the string. The print("CPU", i) statement then prints the string "CPU" followed by the value of i during each iteration of the loop.

Answered By

3 Likes


Related Questions