ProgrammingHardTCS CodeVita · GATE CS · Advanced
What does the following Python 3 code print? print(*[1, 2, 3], *[4, 5], sep=",")
- A. [1, 2, 3],[4, 5]
- B. 1,2,3,4,5
- C. 1 2 3 4 5
- D. 1,2,3 4,5
Correct answer: B. 1,2,3,4,5
Both lists are unpacked into individual positional arguments to print, which joins all five with the given separator.
More Python Programming questions
- 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…
- What does the following Python 3 code print? import itertools print(list(itertools.chain.fromiterable([[1, 2], [3], [4, 5, 6]])))