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'))- A. False False True True
- B. True False True True
- C. True False False True
- 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
- What is printed? python import itertools print(list(itertools.accumulate([1, 2, 3, 4])), list(itertools.accumulate('ab'))…
- What is printed? python print(len([x for x in range(1, 100) if x % 3 == 0 or x % 5 == 0]), sum(x for x in range(1, 100) if x % 3 == 0 or x…
- What is printed? python print(bin(10)[::-1], int(''.join(reversed(bin(10)[2:])), 2), format(10, 'b').zfill(6))
- What is printed? python from collections import Counter c = Counter(a=1) c.subtract({'a': 3, 'b': 1}) print(c, c['a'] + c['b'])
- What is printed? python print(sorted([(2, 'b'), (1, 'z'), (3, 'a')], reverse=True))
- What is printed? python print(3 in {1, 2, 3} and 'x' in 'xyz', [] or () or None)