ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
x = 'aXbX'
print(x.split('X'), x.partition('X')[0] + x.rpartition('X')[2])- A. ['aX', 'bX'] ab
- B. ['a', 'b', ''] a
- C. ['a', 'b'] ab
- D. ['a', 'b', ''] aX
Correct answer: B. ['a', 'b', ''] a
split('X') keeps the empty string after the final X. partition('X')[0] is 'a', and rpartition('X')[2] is the empty text after the last X, so the concatenation is 'a'.
More Python Programming questions
- 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))
- What is printed? python print(1 < 2 < 3 > 2 == 2, 1 < 3 < 2, (1 < 3) < 2)
- What is printed? python class Box: def init(self, n): self.n = n def len(self): return self.n def bool(self): return True…
- What is printed? python calls = 0 def expensive(): global calls calls += 1 return 0 d = {'x': 5} for k in ['x', 'y', 'x']: v = d.get(k…