ProgrammingHardIBM · Deloitte pattern
What is printed?
What is printed?
s = "Mississippi"
print(s.count("ss"), s.count("i"))- A. 4 4
- B. 2 4
- C. 2 2
- D. 4 2
Correct answer: B. 2 4
str.count finds NON-overlapping matches: 'ss' appears at positions 2-3 and 5-6, giving 2. The letter 'i' appears at positions 1, 4, 7, 10, giving 4.
More Python Programming questions
- What is printed? python l = [1, 2, 3, 4, 5] l[1:4] = [] print(l)
- What is printed? python class V: def init(self, x): self.x = x def add(self, o): return V(self.x + o.x) def repr(self): return…
- What is printed? python class W: def init(self, x): self.x = x def lt(self, o): return self.x < o.x ws = [W(3), W(1), W(2)] print([w.x for…
- What is printed? python class N: def init(self, v): self.v = v def bool(self): return self.v != 0 n1 = N(0) n2 = N(5) print(bool(n1)…
- What is printed? python class Base: def repr(self): return "Base" class Sub(Base): pass print([Sub(), Sub()])
- What is printed? python class CM3: def enter(self): return 42 def exit(self, et, ev, tb): return False with CM3() as val: print(val)