ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'ab' * 2 + 'c'
print(s.endswith('bc'), s.startswith('ab', 2), s.find('ab', 1), s.count('ab'))- A. True False 2 2
- B. True True 2 2
- C. True True 0 2
- D. False True 2 2
Correct answer: B. True True 2 2
The string is 'ababc', so it ends with 'bc', and from index 2 it still starts with 'ab'. find from index 1 locates the second 'ab' at index 2, and count gives 2.
More Python Programming questions
- What is printed? python print(len(''.join(str(i) for i in range(1, 11))), ''.join(str(i) for i in range(1, 11))[-3:], sum(len(str(i)) for…
- What is the time complexity of checking whether a number n is prime by trial division up to its square root?
- What is printed? python from string import Template print(Template('a-b').substitute(a=1, b=2), Template('ac').safesubstitute(a='x')…
- What is printed? python try: print((300).tobytes(1, 'big')) except OverflowError: print('overflow') print((255).tobytes(1, 'big')…
- What is printed? python print(bool('0'), bool(0.0), bool(-0.0), bool(float('nan')), bool(' '))
- What is printed? python print(True & 2, True | 2, True ^ True, ~True)