ProgrammingHardAccenture pattern
What is printed?
What is printed?
s = "abcdef" print(s[10:20])
- A. IndexError
- B. ''
- C. None
- D. abcdef
Correct answer: B. ''
A start index far past the string's length clamps to len(s); the whole slice is then empty, so Python returns the empty string instead of raising an error.
More Python Programming questions
- What is printed? python s = "abcdef" s2 = list(s) s2[1:3] = ["X", "Y", "Z"] print("".join(s2))
- 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…