ProgrammingModerateTCS NQT · Infosys

What is printed?

What is printed?
s = 'a-b_c d'
print(s.replace('-', ' ').replace('_', ' ').split(), s.translate({45: None}))
  1. A. ['a', 'b', 'c', 'd'] a-b_c d
  2. B. ['a-b', 'c', 'e'] ab_c d
  3. C. ['a', 'b', 'c', 'd'] ab_c d
  4. 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

Exams that ask this topic