ProgrammingEasyTCS NQT · Wipro pattern

What is printed?

What is printed?
s = "placement"
print(s[2:5])
  1. A. acem
  2. B. lac
  3. C. ace
  4. D. lace

Correct answer: C. ace

Indexing starts at 0: p(0) l(1) a(2) c(3) e(4). A slice s[2:5] takes indices 2, 3 and 4 and stops before 5, giving 'ace'.

More Python Programming questions

Exams that ask this topic