?
What will be the output of the following Python code?
What will be the output of the following Python code?
x = 'abcd'
for i in x:
print(i.upper())
x = 'abcd'
for i in x:
print(i.upper())
Answer & Solution
Correct Answer:
Option
D
In the given code, a string
Then, a
For each character
The
Therefore, the output will be each character of the string
A
B
C
D.
'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.
Join the Discussion
Login to post a comment or share your explanation.
Login