ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'abcabc'
print(s.find('c'), s.find('c', 3), s.rfind('c', 0, 4), s.count('c', 2))- A. 2 2 2 2
- B. 2 5 5 2
- C. 2 5 2 1
- D. 2 5 2 2
Correct answer: D. 2 5 2 2
find returns the first c at index 2. With start 3 it finds the c at 5. rfind searches indices 0 to 3 and returns the c at 2. count from index 2 includes both c's.
More Python Programming questions
- What is printed? python nums = [1, 2, 3, 4, 5] print([nums[i] for i in range(len(nums) - 1, -1, -2)], nums[::-2][0])
- What is printed? python def walk(s): total = 0 for i, ch in enumerate(s, start=1): if ch.isupper(): total += i else: total -= i return…
- What is printed? python print(sum(x for x in range(1, 11) if x & 1), sum(x for x in range(1, 11) if x & 2))
- What is printed? python x = 'AbC' print(x.swapcase(), x.lower() < x.upper(), sorted(x) == ['A', 'C', 'b'])
- What is printed? python print(max(range(5), key=lambda x: -abs(x - 2)), min(range(5), key=lambda x: abs(x - 2)))
- What is printed? python print(sum(divmod(17, 5)), divmod(-17, 5)[1], 17 % 5 - (-17) % 5)