Q46
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
C
D
B.
a b c d
C.
error
D.
A
B
C
D
AnswerB
C
D
Answer: Option D
Solution
Answer: Option D
Solution:
In the given code, a string 'abcd' is assigned to the variable x.Then, a
for loop iterates over each character in the string x.For each character
i, the upper() method is called to convert it to uppercase.The
upper() method converts a string to uppercase.Therefore, the output will be each character of the string
'abcd' converted to uppercase and printed on separate lines: A
B
C
D.