ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
s = 'key=value=end'
print(s.partition('='), s.rpartition('='), 'a b'.split(' '))- A. ('key', '=', 'value') ('key=value', '=', 'end') ['a', 'b']
- B. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', '', 'b']
- C. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', 'bb']
- D. ('key', '=', 'value') ('key=value', '=', 'end') ['b']
Correct answer: B. ('key', '=', 'value=end') ('key=value', '=', 'end') ['a', '', 'b']
partition splits at the first separator and rpartition at the last. split with an explicit space keeps the empty field between two spaces.
More Python Programming questions
- What is printed? python def shift(s, k): return ''.join(chr((ord(c) - 97 + k) % 26 + 97) if c.islower() else c for c in s)…
- What is printed? python def closest3(a, t): a = sorted(a) best = None for i in range(len(a) - 2): l, r = i + 1, len(a) - 1 while l < r: s…
- What is printed? python print(0.0 == -0.0, -0.0, 1e16 + 1 == 1e16, 2 53 + 1 == 2 53)
- What is printed? python import bisect xs = [1, 4, 4, 9] i = bisect.bisectleft(xs, 4) xs.insert(i, 4) print(xs, bisect.bisectright(xs, 4)…
- What is printed? python from collections import deque d = deque(range(5)) d.rotate(-2) print(list(d), d[0], d[-1])
- What is printed? python import heapq h = [] for x in [5, 1, 3]: heapq.heappush(h, x) heapq.heappush(h, 0) print([heapq.heappop(h) for in…