ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print('aaaa'.count('aa'), 'aaaa'.replace('aa', 'b'), len('aaaaa'.split('aa')))- A. 2 b 3
- B. 2 bb 3
- C. 3 bb 3
- D. 2 bb 2
Correct answer: B. 2 bb 3
str.count and replace work on non-overlapping matches, so 'aaaa' has 2 matches of 'aa'. 'aaaaa'.split('aa') gives ['', '', 'a'], which has length 3.
More Python Programming questions
- What is printed? python x = 3.14159 print(f"{x:08.3f}|{x:>8.2e}|{42:#x}|{'ab'!r:>6}")
- What is printed? python print(f"{1234567.891:,.2f}", f"{255:b}", f"{-5:+d}")
- What is printed? python print('-'.join(map(str, [1, 2])) 2, ('ab' 3).count('ba'))
- What is printed? python print('a,,b,'.split(','), ' a b '.split(' '))
- What is printed? python print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))
- What is printed? python print(chr(ord('a') + 27), ord('Z') - ord('A'), chr(0x1F600) == 'U0001F600', len('U0001F600'))