ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
s = "abc" print(s * 0, type(s * 0))
- A. abc <class 'str'> <class 'str'>
- B. <class 'str'>
- C. None <class 'NoneType'>
- D. TypeError
Correct answer: B. <class 'str'>
Multiplying a string by 0 produces the empty string (still of type str), not an error and not None; print shows an empty string followed by <class 'str'>.
More Python Programming questions
- What is printed? python s = "Mississippi" print(s.count("ss"), s.count("i"))
- 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()])