ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
s = 'hello world'
print(s.title().split()[1][::-1], s.rsplit(' ', 1)[0], s.count('o', 5))
  1. A. dlroW hello 1
  2. B. dlroW hello 2
  3. C. wdlro hello 1
  4. D. dlrow world 1

Correct answer: A. dlroW hello 1

title() capitalises each word, so the second word is World, which reversed is dlroW. rsplit on the last space keeps hello, and count from index 5 finds the one o in world.

More Python Programming questions

Exams that ask this topic