ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'mississippi'
print(s.count('ss'), s.count('issi'), s.index('s', 3), s.rindex('i', 0, 5))- A. 2 1 2 4
- B. 2 1 3 1
- C. 2 1 3 4
- D. 2 2 3 4
Correct answer: C. 2 1 3 4
'ss' occurs twice without overlap. 'issi' occurs at positions 1 and 4, which overlap, and count skips overlapping matches, so it reports 1. index('s', 3) is 3, and rindex('i', 0, 5) finds the last i before position 5, at index 4.
More Python Programming questions
- What is printed? python import math print(math.isqrt(10 12), math.isqrt(2 10 12) 2 <= 2 10 12)
- What is printed? python def fact(n): return 1 if n <= 1 else n fact(n - 1) print(len(str(fact(25))), fact(25) % 10 6 == 0, fact(25) % 7)
- What is printed? python x = 'aXbX' print(x.split('X'), x.partition('X')[0] + x.rpartition('X')[2])
- What is printed? python print(2 200 % 7 == pow(2, 200, 7), len(str(2 200)), 2 200 % 7)
- What is printed? python s = 'abc' t = s 2 print(t[::2], t[1::3], t.find('ca'), t.count('b'))
- What is printed? python d = {'a': 1} keys = d.keys() d['b'] = 2 del d['a'] print(list(keys), len(keys))