ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
s = 'x' * 3
print(s * -1 == '', s.replace('x', 'xy', 2), s.count('xx'), s.index('x', 1))- A. True xyxyxx 1 1
- B. False xyxyx 1 1
- C. True xyxyx 2 1
- D. True xyxyx 1 1
Correct answer: D. True xyxyx 1 1
A negative repeat count gives the empty string. replace with a count of 2 changes only the first two x characters, and count('xx') does not overlap, so it finds one match.
More Python Programming questions
- What is printed? python print(' '.join(str(i) for i in range(3)), ','.join(f'{i:02d}' for i in (1, 10)), '|'.join(['x']), ''.join([''…
- What is printed? python print(max(3, 3.0), max(3.0, 3), min(-0.0, 0), min(0, -0.0))
- What is printed? python print('abc'[1:][::-1], 'abc'[::-1][1:], 'abcdef'[::-2][:2])
- What is printed? python print(float('nan') != float('nan'), float('inf') == float('inf'), float('inf') - float('inf') == 0, -float('inf')…
- What is printed? python x = [1, 2, 3] y = x x = x + [4] print(y, x, y is x)
- What is printed? python print(int('٤٢'), '٤٢'.isnumeric(), ' 42n'.isdigit(), int('42n'))