निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।
Find the output of the following Python programs.
x=['ab','cd']
for i in x:
i.upper()
print(x)
Explanation:
-
The
upper()
method: Theupper()
method returns a new string with all characters in uppercase. However, strings in Python are immutable, meaning that callingupper()
on a string does not modify the original string in place. Instead, it returns a new string. In the loop, the result ofi.upper()
is not assigned to any variable or used, so it has no effect on the original listx
. -
The loop: The loop iterates through each string in the list
x
. For each string,i.upper()
is called, but since the result is not used, the strings in the listx
remain unchanged. -
Printing the list
x
: After the loop finishes, the listx
remains as['ab', 'cd']
because no modifications have been made to it.