ProgrammingEasyTCS NQT · Infosys pattern

What is printed?

What is printed?
s = "Python"
print(s.find("th"), s.find("z"), s.upper()[1:3])
  1. A. 2 None YT
  2. B. 3 -1 YT
  3. C. 2 -1 YTH
  4. D. 2 -1 YT

Correct answer: D. 2 -1 YT

find returns the index where the substring starts ("th" starts at index 2) and -1 when it is absent; it never returns None (index() would raise ValueError). "PYTHON"[1:3] takes indices 1 and 2: "YT".

More Python Programming questions

Exams that ask this topic