ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
print('abcdef'[4:1:-2], 'abc'[::-2], 'abc'[-5:], 'abc'[5:] == '')- A. ec ca abc False
- B. ce ca abc True
- C. ec ac abc True
- D. ec ca abc True
Correct answer: D. ec ca abc True
A negative step walks backward from index 4, taking indices 4 and 2 to give 'ec'. 'abc'[::-2] takes indices 2 and 0 to give 'ca', and a start index past the end gives an empty slice.
More Python Programming questions
- What is printed? python import cmath print((-1) 0.5 == 1j, -1 0.5, (-1) 0.5)
- What is printed? python print((-7) % 3, 7 % -3, (-7) % -3, -7 % 3 2)
- What is printed? python print(-6 & 0xFF, -6 | 3, -6 ^ -3, ~-6 >> 1)
- What is printed? python print(len('ab' 3 0 + 'c'), ('%5.2f' % 3.14159).strip(), '%-5s|' % 'ab', '%05d' % -42)
- What is printed? python print(-7 // 2, -7 % 2, -7 // 2 2 + -7 % 2)
- What is printed? python print(7 // -2, -7 // 2, 7 % -2, divmod(-7, -2))