ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
print('abc'.index('c'), 'abcabc'.rfind('b'), 'abc'.find('d'), len('abc'[1:]))- A. 2 4 0 2
- B. 2 5 -1 2
- C. 2 4 -1 2
- D. 3 4 -1 2
Correct answer: C. 2 4 -1 2
index finds the first c at position 2, and rfind returns the last b at position 4. find returns -1 when the substring is missing, and slicing from position 1 leaves two characters.
More Python Programming questions
- What is printed? python print(sorted('bca'), ''.join(sorted('bca', reverse=True)), sorted([3, 1, 2], reverse=True)[0], list(reversed('ab')))
- What is printed? python print(int('12') + int('3'), '12' + '3', 12 + 3 == int('15'), 'x')
- What is printed? python s = 'Python' print(s[0], s[-1], s[1:4], s[::2])
- What is printed? python print(len([1, 2, 3] 2), [1, 2] + [3], [0] 0, [[0] 2] 2 == [[0, 0], [0, 0]])
- What is printed? python print('Hello'.lower() == 'hello', 'Hello'.islower(), 'hello'.isalpha(), 'h3llo'.isalnum())
- What is printed? python print(0.1 + 0.2 > 0.3, round(0.1 + 0.2, 2) == 0.3, 3 0.1 == 0.3, 1 / 3 3 == 1)