CBSE Class 11 Informatics Practices Question 25 of 75

Conditional and Looping Constructs — Question 7

Back to all questions
7
Question

Question 7

What will be the output?

x = ['ab', 'cd']
for i in x:
   i.upper()
print (x)
  1. ['ab', 'cd']
  2. ['AB', 'CD']
  3. [None, None]
  4. None of these
Answer

['ab', 'cd']

Reason — In the given code, the for loop iterates over the list x containing strings 'ab' and 'cd'. Inside the loop, i.upper() is called, which returns a new string in uppercase but doesn't modify i itself because strings in Python are immutable. Therefore, i.upper() doesn't change i or x in place. After the loop finishes, x remains unchanged, so the output is ['ab', 'cd'].