ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
s = "placement" print(s[-100:5])
- A. IndexError
- B. place
- C. ''
- D. lacem
Correct answer: B. place
Slice bounds are clamped, never raising IndexError: -100 clamps to 0, and the slice becomes s[0:5], which is 'place'.
More Python Programming questions
- What is printed? python s = "abcdef" print(s[10:20])
- 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…