ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
def f(s):
    return s.lower() == s[::-1].lower()
print(f('Aba'), f('Ab'), f(''), f('A'))
  1. A. False False True True
  2. B. True False True True
  3. C. True False False True
  4. D. True True True True

Correct answer: B. True False True True

Lowercasing before comparing makes the check case-insensitive, so 'Aba' is a palindrome. The empty string and a single letter are trivially palindromes, while 'Ab' is not.

More Python Programming questions

Exams that ask this topic