ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(('ab' * 3).count('aba'), 'ababa'.count('aba'), 'aaaa'.count('aa'))- A. 2 2 2
- B. 1 2 2
- C. 1 1 2
- D. 2 1 2
Correct answer: C. 1 1 2
str.count scans left to right and counts non-overlapping matches, so 'ababab' and 'ababa' each contain one 'aba' and 'aaaa' contains two 'aa'. Counting overlapping matches would give 2 for the first case.
More Python Programming questions
- What is printed on the third line? python print('a,b,,c'.split(',')) print(' a b '.split()) print(' a b '.split(' '))
- What is printed? python print(int('0x1f', 16), int('0x1f', 0), int(' -12 '), int('1000'))
- What is printed? python print(bin(-5), format(-5, '08b'), (-5) & 0xFF, format(-5 & 0xFF, '08b'))
- What is printed? python print(divmod(-17, 5), divmod(17, -5), divmod(-17.0, 5))
- What is printed? python print(7 // -2, -7 // 2, 7.0 // -2, -7.0 % 2)
- What is printed? python print(abs(-0.0), -0.0 == 0.0, str(-0.0), str(-0.0 + 0.0))