ExamVeda
Login
Home
Introduction to Python
?

What will be the output of the following Python code?
x = 'abcd'
for i in x:
    print(i.upper())

Answer & Solution
Correct Answer: Option D
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
.
Examveda
Question posted by Examveda
Community

Join the Discussion

No comments yet Be the first to discuss this question.