ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
s = 'a-b_c d'
print(s.replace('-', ' ').replace('_', ' ').split(), s.translate({45: None}))- A. ['a', 'b', 'c', 'd'] a-b_c d
- B. ['a-b', 'c', 'e'] ab_c d
- C. ['a', 'b', 'c', 'd'] ab_c d
- D. ['a', 'b', 'c d'] ab_c e
Correct answer: C. ['a', 'b', 'c', 'd'] ab_c d
Replacing '-' and '_' with spaces and then calling split() gives four words. translate with the mapping 45 (which is '-') to None deletes only the hyphen, so the underscore stays.
More Python Programming questions
- What is printed? python print('abc'.index('c') + 'abc'.rindex('a'), 'aXbXc'.rsplit('X', 1), 'a b'.title())
- 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])))