ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print('1.2.3.4'.rsplit('.', 1), 'x'.partition('='), 'a=b=c'.partition('='))- A. ['1.2.3', '4'] ('x', 'x', '') ('a', '=', 'b=c')
- B. ['1.2.3', '4'] ('x', '', '') ('a', 'b', 'd')
- C. ['1.2.3', '4'] ('x', '', '') ('a', '=', 'b=c')
- D. ['1.2', '3.4'] ('x', '', '') ('a', '=', 'b')
Correct answer: C. ['1.2.3', '4'] ('x', '', '') ('a', '=', 'b=c')
rsplit with maxsplit=1 splits from the right, giving ['1.2.3', '4']. partition returns (before, separator, after) and gives empty strings when the separator is missing. It splits only at the first '='.
More Python Programming questions
- What is printed? python print(chr(ord('a') + 27), ord('Z') - ord('A'), chr(0x1F600) == 'U0001F600', len('U0001F600'))
- Which of the following Python operations on a built-in container is O(1) on average (independent of the container size)?
- Timsort is the algorithm behind Python's sorted(). For an input that is already in ascending order, what is its running time?
- What is printed? python print(10 17 in range(0, 10 18, 2), 10 17 + 1 in range(0, 10 18, 2))
- What is printed? python def add(x, memo={}): memo[x] = len(memo) return memo print(add(5), add(7))
- What is printed? python print(min('10', '9'), min(10, 9), max('10', '9', key=int))