ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE

What does the following Python 3 code print? s = "banana split" print("-".join(s.split("n")[1:]))

  1. A. ba-ana split
  2. B. ba-a-a split
  3. C. ba-a
  4. D. a-a split

Correct answer: D. a-a split

split removes every occurrence of the separator; [1:] drops the first fragment; join glues the rest with '-'. Output: a-a split.

More Python Programming questions

Exams that ask this topic