ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'hello'
print(s.index('l'), s.rfind('l'), s.find('l', 3), s.index('lo'))- A. 2 3 -1 3
- B. 2 2 3 3
- C. 3 3 3 3
- D. 2 3 3 3
Correct answer: D. 2 3 3 3
index and find return the first match from the left, which is 2. rfind gives the last l at 3. find from index 3 still finds the l at 3. 'lo' starts at index 3.
More Python Programming questions
- What is printed? python import itertools print(sum(1 for in itertools.combinations(range(6), 2)), sum(1 for in…
- Which of the following statements about Python's sort is correct for CP problems?
- What is printed? python def solve(n): if n == 0: return [] return solve(n // 2) + [n % 2] print(solve(6), solve(0))
- What is printed? python print(divmod(7, -3), 7 % -3, -7 % 3, -7 // 3)
- What is printed? python x = 'aaa' y = list(x) y[0] = 'b' print(x, ''.join(y), x is y)
- What is printed? python grid = [[1, 2], [3, 4]] flat = [v for row in grid for v in row] print(flat, sum(flat) == sum(map(sum, grid)))