ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
s = "level"
t = "".join(reversed(s))
u = s[::-1]
print(s == t == u, t is s, list(reversed([1, 2])) == [2, 1], reversed("ab") == reversed("ab"))
  1. A. True True True True
  2. B. True False True True
  3. C. False False True False
  4. D. True False True False

Correct answer: D. True False True False

'level' is a palindrome, so all three are equal. join builds a new string object. reversed() returns iterator objects, and two distinct iterators compare by identity, so False.

More Python Programming questions

Exams that ask this topic