ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
s = 'Python'
print(s[0], s[-1], s[1:4], s[::2])
  1. A. P n yth Pto
  2. B. P n yt Pto
  3. C. P n yth Pyo
  4. D. P n yth Pt

Correct answer: A. P n yth Pto

s[1:4] takes indices 1, 2 and 3, which gives yth. s[::2] takes every second character, P, t and o.

More Python Programming questions

Exams that ask this topic