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))- A. dlroW hello 1
- B. dlroW hello 2
- C. wdlro hello 1
- 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
- What is printed? python print(int(0.1 10), round(0.1 10, 10) == 1, 0.1 10 == 1)
- What is printed? python print(abs(-0.0), abs(-3), abs(True), abs(-2 63))
- What is printed? python print(bool(0.0 or 0j), bool(0j or 1j), 0j == 0, 1j 1j)
- What is printed? python print([x for x in range(5) if x % 2], [x for x in 'a1b2' if x.isdigit()], {x % 3 for x in range(6)})
- What is printed? python print(str(()), str([()]), repr(('a',)), str(('a', 1)))
- What is printed? python x = 10 def f(): return x x = 20 print(f(), (lambda y=x: y)(), [lambda: i for i in range(2)][1]())