ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
a = 'ab'
b = a * 3
print(b.count('ab'), b.count('aba'), len(b.split('b')))- A. 3 1 4
- B. 3 2 4
- C. 3 1 3
- D. 2 1 4
Correct answer: A. 3 1 4
'ababab' contains three non-overlapping 'ab' pairs and one 'aba' match. Splitting on 'b' gives four pieces, including the empty piece at the end.
More Python Programming questions
- What is printed? python print(0.1 10 == 1.0, 0.1 10, sum([0.1] 10) == 1)
- What is printed? python print(int(1e15 + 0.3) == 1015, round(1e15 + 0.3) - 1015)
- What is printed? python print(10.01, 0x1F, 1000.0e-3)
- What is printed? python print(str(1e100)[:6], len(str(1e100)), 1e100 == 10100)
- What is printed? python print(divmod(-1, 1020), divmod(1020, -1))
- What is printed? python print(int(1e20) == 1020, int(1e20 + 1) == 1020 + 1, int(1e20) - 1020)