ProgrammingVery hardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'abc'
t = s * 2
print(t[::2], t[1::3], t.find('ca'), t.count('b'))- A. acb bc -1 2
- B. ac bb 2 1
- C. acb ab 2 2
- D. acb bb 2 2
Correct answer: D. acb bb 2 2
t is 'abcabc'. Its even indices give 'acb'. [1::3] takes indices 1 and 4, which are both 'b', so it gives 'bb'. 'ca' starts at index 2, and 'b' appears twice.
More Python Programming questions
- 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…
- What is printed? python d = {'a': 1, 'b': 2, 'c': 3} try: for k in d: if d[k] == 2: del d[k] except RuntimeError: print('error')…
- What is printed? python a = [1, 2, 2, 3, 4] for x in a: if x == 2: a.remove(x) print(a)