ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
print('abc'.index('c') + 'abc'.rindex('a'), 'aXbXc'.rsplit('X', 1), 'a b'.title())- A. 3 ['aXb', 'c'] A B
- B. 2 ['a', 'bXc'] A B
- C. 2 ['aXb', 'c'] A c
- D. 2 ['aXb', 'c'] A B
Correct answer: D. 2 ['aXb', 'c'] A B
index('c') is 2 and rindex('a') is 0, giving 2. rsplit with maxsplit 1 splits only at the last X, and title capitalises each word.
More Python Programming questions
- What is printed? python import string print(string.asciilowercase.index('z'), string.digits[::-1][:3], string.asciiuppercase[25] +…
- What is printed? python print(int('1' 30) % 97, pow(10, 30, 97), (1030 - 1) // 9 % 97)
- What is printed? python print(sum(int(c) for c in str(21000)), len(str(21000)))
- What is printed? python print(len(set(str(i i) for i in range(10))), sorted([(-1) i i for i in range(6)]))
- What is printed? python print(list(map(round, [0.5, 1.5, 2.5, -0.5, -1.5])), list(map(int, [0.5, 1.5, 2.5, -0.5, -1.5])))
- What is printed? python print(max(['10', '9']), max(['10', '9'], key=len), sorted(['10', '9', '100'], key=lambda s: (len(s), s)))