ProgrammingHardTCS NQT · Wipro pattern
What is printed?
What is printed?
s = 'abcdef' print(s[-2:], s[:-2], s[-10:], s[::-2][0])
- A. ef abcd abcde f
- B. fe abcd abcdef f
- C. ef abcd abcdef e
- D. ef abcd abcdef f
Correct answer: D. ef abcd abcdef f
s[-2:] is ef, and s[:-2] drops the last two characters to give abcd. A start index far before the beginning clamps to the whole string, and reversing with step -2 begins at f.
More Python Programming questions
- What is printed? python print('abc' < 'abd' and 'x' or 'y', [] or 'empty', 0 or 0.0 or 'z')
- What is printed? python print(len({'a': 1, 'a': 2}), {'a': 1, 'a': 2}, list({1, 2, 1}), sorted({3, 1, 2} & {2, 3, 4}))
- What is printed? python print('Ab'.swapcase(), 'ab'.capitalize() == 'Ab', 'AB'.lower() == 'ab', 'a b'.title())
- What is printed? python print(3 > 2 > 1, 3 > 2 and 2 > 1, (3 > 2) + (2 > 1))
- What is printed? python print(sorted([0.5, 1, True, False]), max(0.5, 1, True))
- What is printed? python print('%s|%s' % ('a', 'b'), 'ok', '%5.1f%%' % 99.55)