ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print('abcabc'.find('c', 3, 5), 'abcabc'.rfind('a', 0, 4))- A. -1 3
- B. 5 3
- C. -1 0
- D. 2 3
Correct answer: A. -1 3
find only searches the slice from index 3 up to 5, which is ab, so it returns -1. rfind searches indices 0 to 3, and the last a in that range is at index 3.
More Python Programming questions
- What is printed? python d = {'a': {'b': 1}} print(d.get('a', {}).get('c', 0), d.get('x', {}).get('b'), d['a'].get('b'))
- What is printed? python import math def ndiv(n): c = 0 for i in range(1, math.isqrt(n) + 1): if n % i == 0: c += 1 if i i == n else 2…
- What is printed? python class N: def init(self, v, nxt=None): self.v, self.nxt = v, nxt def mid(h): slow = fast = h while fast and…
- What is printed? python from collections import Counter print(''.join(c n for c, n in Counter('tree').mostcommon()))
- What is printed? python import itertools print(len(set(itertools.permutations('aab'))), len(list(itertools.permutations('aab'))))
- What is printed? python print(list(zip([iter(range(6))] 2)))