ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
s = "abcdef"
s2 = list(s)
s2[1:3] = ["X", "Y", "Z"]
print("".join(s2))- A. aXYZdef
- B. aXYdef
- C. aXYZcdef
- D. abXYZdef
Correct answer: A. aXYZdef
Slice assignment to a list can change its length: it removes the two elements at indices 1 and 2 ('b', 'c') and splices in three new elements ('X', 'Y', 'Z') in their place, giving a['X','Y','Z']def joined as aXYZdef.
More Python Programming questions
- What is printed? python s = "abc" print(s 0, type(s 0))
- 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)…