ProgrammingModerateTCS NQT · Wipro pattern
What is printed?
What is printed?
s = 'hello'
print(s.index('l'), s.rindex('l'), s.find('z'), s.count('l'))- A. 2 3 0 2
- B. 2 4 -1 2
- C. 2 3 -1 1
- D. 2 3 -1 2
Correct answer: D. 2 3 -1 2
index and rindex find the first and last l, at positions 2 and 3. find returns -1 when the text is missing, while index would raise ValueError. count gives the number of l characters.
More Python Programming questions
- What is printed? python print(int(str(264) 0 + '7') 2, len(str(7 100)), 7 100 % 10)
- What is printed? python from itertools import product print(list(map(''.join, product('ab', repeat=2))))
- What is printed? python print(sum(range(10 6)) % 1000, sum(range(1, 11)) // 5)
- What is printed? python print(('a' 'b' 'c').upper(), 'x' 'y' 2, ('%d' % 3) 2)
- What is printed? python print(1e16 == 1016, 1e16 + 1 == 1016 + 1, 1e16 + 2 == 1016 + 2, int(1e16) + 1)
- What is printed? python print('%.2e' % 0, '%.1f' % 2.25, '%.1f' % 2.35, '%5.1f|' % -0.04)