ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print('abcabc'.replace('abc', 'x', 1), 'aaaa'.replace('aa', 'b'), 'aaa'.replace('', '-'))- A. xabc bb -a-a-
- B. xbc bb -a-a-a-
- C. xabc b -a-a-a-
- D. xabc bb -a-a-a-
Correct answer: D. xabc bb -a-a-a-
The count argument limits replacements to the first match. Non-overlapping replacement turns aaaa into bb, and replacing the empty string inserts a dash before and after each character.
More Python Programming questions
- What is printed? python print('Mississippi'.lower().count('s'), 'Mississippi'.find('ss'), 'Mississippi'.rfind('ss'))
- What is printed? python print(float('-0') == 0.0, str(float('-0')), str(float('+0')))
- What is printed? python print(sum(1 for i in range(1, 1001) if '7' in str(i)))
- What is printed? python print(int(str(12345)[::-1]) - 12345, 12345 - int(str(12345)[::-1]))
- What is printed? python print(len(bin(-1)), len(hex(255)), oct(64))
- What is printed? python print(int('12abc', 16), int('ABC', 16) == 0xabc, int('1000000') == 106)