ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
print('abc'[-1:-4:-1], 'abc'[5:], 'abc'[-10:2])- A. cbaab
- B. cba a
- C. cba ab
- D. cba ba
Correct answer: C. cba ab
The reversed slice gives cba, the slice past the end gives an empty string, and the slice from a very negative start gives ab. print puts a space before each empty string, leaving two spaces.
More Python Programming questions
- What is printed? python print(ord('A') + 1, chr(ord('a') - 32))
- What is printed? python print(divmod(7, -2), 7 % -2)
- What is printed? python print(sum([[1], [2, 3]], []))
- What is printed? python x = (1, [2]) x[1].append(3) print(x)
- What is printed? python print(max([1, 5, 3], key=lambda v: -v))
- What is printed? python print(list(map(int, '1 2 3'.split()))[::-1])