ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
a = 'Python'
print(a[::-1][1:4], a[-2:] + a[:2], a.upper()[::2])
  1. A. oht Pyon PTO
  2. B. oht onPy PYT
  3. C. hto onPy PTO
  4. D. oht onPy PTO

Correct answer: D. oht onPy PTO

a[::-1] is 'nohtyP', and [1:4] of that is 'oht'. a[-2:] + a[:2] is 'on' + 'Py'. upper() gives PYTHON and [::2] takes indices 0, 2, 4, which are P, T and O.

More Python Programming questions

Exams that ask this topic