ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
word = 'Level' print(word.lower() == word.lower()[::-1], word == word[::-1], word.casefold() == 'level')
- A. True False False
- B. True False True
- C. False False True
- D. True True True
Correct answer: B. True False True
lower() makes the comparison case-insensitive, so the palindrome check on 'level' is True. The raw word Level is not equal to its reverse, because the first letter is uppercase. casefold gives 'level'.
More Python Programming questions
- What is printed? python d = {} for w in ['b', 'a', 'b']: d[w] = d.get(w, 0) + 1 print(d, max(d, key=d.get), sorted(d.values()…
- Which is the time complexity of checking whether a string s of length n is a palindrome, using s == s[::-1]?
- What is printed? python values = [0, 1, 2, 3] print([v for v in values if v] == values[1:], any(values), all(values[1:]))
- What is printed? python import heapq nums = [7, 2, 9] heapq.heapify(nums) print(nums[0], heapq.nlargest(1, nums)[0], heapq.nsmallest(2…
- What is printed? python print(any(x > 3 for x in range(10)), next(x for x in range(10) if x x > 20), sum(x for x in range(0, 10, 4)))
- What is printed? python s = '12:34:56' h, m, sec = map(int, s.split(':')) print(h 3600 + m 60 + sec, divmod(h 3600 + m 60 + sec, 60))