ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print('ab'.startswith(('x', 'a')), 'abc'.endswith('', 3), 'abc'.index('c', -1), 'aXbX'.split('X', 1))- A. True False 2 ['a', 'bX']
- B. True True 2 ['a', 'b', '']
- C. True True 2 ['a', 'bX']
- D. False True 2 ['a', 'bX']
Correct answer: C. True True 2 ['a', 'bX']
startswith accepts a tuple of prefixes. An empty suffix always matches, and the start index 3 is the end of the string, so the test is True. split with maxsplit 1 stops after the first separator.
More Python Programming questions
- What is printed? python print(ord('A') + 1, chr(ord('a') + 25), chr(0x1F600) == 'U0001F600', len('U0001F600'), 'N{SNOWMAN}')
- What is printed? python from functools import cmptokey w = ['bb', 'a', 'ccc', 'ab', 'c'] def c(x, y): if len(x) != len(y): return len(x)…
- What is printed? python from collections import deque g = ["..#", ".#.", "..."] d = [[-1] 3 for in range(3)] q = deque([(0, 0)]) d[0][0] =…
- What is printed? python import bisect a = sorted([5, 1, 9, 3, 7]) print(bisect.bisectright(a, 7) - bisect.bisectleft(a, 4))
- What is printed? python from collections import defaultdict d = defaultdict(list) d['a'] print('a' in d, len(d), d.get('b'), 'b' in d)
- What is printed? python from functools import cache @cache def paths(r, c): return 1 if r == 0 or c == 0 else paths(r - 1, c) + paths(r, c…