ProgrammingHardTCS CodeVita · Infosys HackWithInfy · Product Company SDE
What does the following Python 3 code print? s = "banana split" print("-".join(s.split("n")[1:]))
- A. ba-ana split
- B. ba-a-a split
- C. ba-a
- 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
- What does the following Python 3 code print? from functools import lrucache calls = 0 @lrucache(None) def f(n): global calls calls += 1…
- What does the following Python 3 code print? a, b = set([12,12,1,7,1]), set([12,12,3,10,6,10]) print(sorted(a ^ b), len(a - b))
- What does the following Python 3 code print? def mk(): c = 0 def inc(): nonlocal c c += 2 return c return inc a, b = mk(), mk() for in…
- What does the following Python 3 code print? a, b, c = 25, 3, 17 print((a << b) ^ c, a & ~c, (a | c) >> b)
- What does the following Python 3 code print? def f(): try: return 7 finally: print("f", end=" ") x = f() + 13 print(x)
- What does the following Python 3 code print? a, b = [3,1,8,5,4,7], [7,4,2,5] print(list(map(lambda p: p[0] p[1], zip(a, b)))…