ProgrammingHardWipro · Accenture · Capgemini pattern
What does the following Python 3 code print? print(list(enumerate(["a", "b", "c"], start=1)))
- A. [(0, 'a'), (1, 'b'), (2, 'c')]
- B. [('a', 1), ('b', 2), ('c', 3)]
- C. [(1, 'a'), (2, 'b'), (3, 'c')]
- D. [(1, 'a'), (2, 'b')]
Correct answer: C. [(1, 'a'), (2, 'b'), (3, 'c')]
The start=1 argument makes the index counter begin at 1 instead of the default 0.
More Python Programming questions
- What does the following Python 3 code print? print(dict(enumerate(["x", "y", "z"])))
- What does the following Python 3 code print? a = {1, 2, 3} b = {2, 3, 4} print(a & b, a | b, a - b, a ^ b)
- What does the following Python 3 code print? a = frozenset([1, 2, 3]) try: a.add(4) except AttributeError: print("AttributeError")
- What does the following Python 3 code print? s = set([1, 2, 2, 3, 3, 3]) print(sorted(s), len(s))
- What does the following Python 3 code print? class Node: def init(self, v, nxt=None): self.v = v; self.nxt = nxt n3 = Node(3) n2 = Node(2…
- What does the following Python 3 code print? def fib(n, memo={}): if n in memo: return memo[n] if n <= 1: return n memo[n] = fib(n - 1…