CBSE Class 12 Computer Science Question 86 of 105

Python Revision Tour — Question 12

Back to all questions
12
Question

Question 2k

Predict the output of the following code fragments:

for x in 'lamp':
    print(str.upper(x))
Answer
Output
L
A
M
P
Explanation

The for loop extracts each letter of the string 'lamp' one by one and place it in variable x. Inside the loop, x is converted to uppercase and printed.