ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
t = 'racecar'
print(t == t[::-1], t.find('car'), t.rfind('c'), t.replace('car', 'CAR', 1))- A. True 4 4 raceCAT
- B. False 4 4 raceCAR
- C. True 4 5 raceCAR
- D. True 4 4 raceCAR
Correct answer: D. True 4 4 raceCAR
'racecar' reads the same both ways, and find returns the first 'car' at index 4. rfind('c') also finds index 4, and replace with a count of 1 changes only the first match.
More Python Programming questions
- What is printed? python s = 'one two three' print(s.split(' '), len(s.split()), s.split(None, 1)[1], '-'.join(s.split()))
- What is printed? python print('ab'.ljust(4, '') + '|', 'ab'.rjust(4, ''), 'ab'.zfill(4), '12'.zfill(1))
- What is printed? python print('%s and %s' % ('A', 'B'), '%(x)d-%(x)05.1f' % {'x': 3}, '%%%d' % 5)
- What is printed? python print(1 / 2 + 1 // 2 + 1 % 2, 1 / 2 2 == 1, 3 1 / 2 == 3 (1 / 2))
- What is printed? python print(0x10 + 0o10 + 0b10, 10 + 0x1, 1e1 + 1, 1j 1j)
- What is printed? python print(max(-0.0, 0), min(0, -0.0), -0.0 + 0, 0 - 0.0)