ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
x = 'abc'
y = x.upper()
z = x.upper().lower()
print(y, z == x, x.upper().upper() == y, len(y + z))
  1. A. ABC False True 3
  2. B. abc True False 6
  3. C. ABC True True 3
  4. D. ABC True True 6

Correct answer: D. ABC True True 6

upper() gives ABC, and lower() of that matches the original abc, so the comparison is True. The second upper() call gives ABC again, and the two strings together have six characters.

More Python Programming questions

Exams that ask this topic