ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
s = 'banana'
print(s.find('an', 2), s.rfind('an'), s.find('x'), s.index('na', 3))- A. 3 3 -1 4
- B. 1 3 -1 2
- C. 3 3 -1 2
- D. 3 5 -1 4
Correct answer: A. 3 3 -1 4
'an' occurs at indices 1 and 3, so find from index 2 gives 3 and rfind gives 3. 'na' occurs at 2 and 4, so index('na', 3) gives 4. find returns -1 when the substring is absent.
More Python Programming questions
- What is printed? python print('aaaa'.count('aa'), 'aaaa'.replace('aa', 'b'), len('aaaaa'.split('aa')))
- What is printed? python x = 3.14159 print(f"{x:08.3f}|{x:>8.2e}|{42:#x}|{'ab'!r:>6}")
- What is printed? python print(f"{1234567.891:,.2f}", f"{255:b}", f"{-5:+d}")
- What is printed? python print('-'.join(map(str, [1, 2])) 2, ('ab' 3).count('ba'))
- What is printed? python print('a,,b,'.split(','), ' a b '.split(' '))
- What is printed? python print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))