ProgrammingHardAccenture · Cognizant · Python
What does the following Python 3 code print? d = {"a": 1, "b": 2} print(*d)
- A. a 1 b 2
- B. {'a', 'b'}
- C. ('a', 'b')
- D. a b
Correct answer: D. a b
Unpacking a dict with * iterates over its keys, so print receives 'a' and 'b' as two separate arguments.
More Python Programming questions
- 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]])))
- What does the following Python 3 code print? import itertools print(list(itertools.product([1, 2], [3, 4])))