निम्नलिखित कोड का आउटपुट क्या होगा?
What will be the output of following code ?
x = ['XX', 'YY']
for i in x
i.lower()
print(x)
A)
B)
C)
D)
Explanation:
Let's break down the code step by step:
x = ['XX', 'YY']
for i in x:
i.lower()
print(x)
Explanation:
-
List
x
: The listx = ['XX', 'YY']
contains two strings:'XX'
and'YY'
. -
The
for
loop:- The loop goes through each element in
x
, and for each stringi
, it calls thelower()
method. However,lower()
does not modify the string in place. Strings are immutable in Python, meaning thelower()
method returns a new string but does not change the original one.
- The loop goes through each element in
-
The
print(x)
:- After the loop completes, the list
x
is still unchanged becauselower()
was applied to each string but its result was not stored back inx
.
- After the loop completes, the list
Thus, the list x
remains as ['XX', 'YY']
.
Answer:
(A) ['XX', 'YY']