ProgrammingModerateTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
print('-'.join(map(str, [1, 2])) * 2, ('ab' * 3).count('ba'))- A. 1-21-2 2
- B. 1-2-1-2 2
- C. 1-21-2 3
- D. 1-21-2 1
Correct answer: A. 1-21-2 2
'-'.join gives '1-2', and multiplying by 2 concatenates two copies. 'ababab' contains 'ba' at positions 1 and 3, so count is 2.
More Python Programming questions
- 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('='))
- 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))