निम्नलिखित पायथन प्रोग्राम का आउटपुट खोजें।
Find the output of the following Python programs.
x=['ab','cd']
for i in x:
i.upper()
print(x) -
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 listxremain unchanged. -
Printing the list
x: After the loop finishes, the listxremains as['ab', 'cd']because no modifications have been made to it. -
स्ट्रिंग के मेथड जैसे
upper()मूल स्ट्रिंग को नहीं बदलते (क्योंकि स्ट्रिंग Immutable होती है)। जब तक आपi = i.upper()नहीं करते और उसे वापस लिस्ट में नहीं डालते, लिस्ट वैसी ही रहेगी।
Correct Answer: C) ['ab','cd']