ProgrammingHardInfosys HackWithInfy · TCS CodeVita
What does the following Python 3 code print? l = [1, 2, 3] print(*l, sep="-")
- A. 1-2-3-
- B. 1 2 3
- C. [1, 2, 3]
- D. 1-2-3
Correct answer: D. 1-2-3
The * unpacks the list into three separate arguments to print, joined with the given sep instead of the default space.
More Python Programming questions
- What does the following Python 3 code print? print([1, 2, 3], [4, 5], sep=",")
- What does the following Python 3 code print? d = {"a": 1, "b": 2} print(d)
- What does the following Python 3 code print? a, b, c = [1, 2, 3, 4, 5] print(a, b, c)
- What does the following Python 3 code print? def power(base, exp=2): return base exp print(power(3), power(3, 3), power(exp=3, base=2))
- What does the following Python 3 code print? class Stack: def init(self): self.items = [] def len(self): return len(self.items) def…
- What does the following Python 3 code print? class Range2: def init(self, n): self.n = n def getitem(self, i): if i >= self.n: raise…