ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
word = 'level'
print(word == word[::-1], 'ab' * 2 == 'abab', list('ab') == ['a', 'b'], ('a',) * 0 == ())
  1. A. True True True True
  2. B. True False True True
  3. C. False True True True
  4. D. True True False True

Correct answer: A. True True True True

level reads the same backwards, so the first check holds. Repetition builds the same string, and list('ab') equals ['a', 'b']. Repeating a one-tuple zero times gives an empty tuple, which equals ().

More Python Programming questions

Exams that ask this topic