ProgrammingHardHCL · Tech Mahindra · Python placement
What does the following Python 3 code print? print(dict(enumerate(["x", "y", "z"])))
- A. {0: 'x', 1: 'y', 2: 'z'}
- B. {1: 'x', 2: 'y', 3: 'z'}
- C. {'x': 0, 'y': 1, 'z': 2}
- D. {0: 'x', 1: 'y'}
Correct answer: A. {0: 'x', 1: 'y', 2: 'z'}
enumerate pairs each element with its 0-based index; dict() turns those (index, value) pairs into key:value entries.
More Python Programming questions
- 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…
- What does the following Python 3 code print? def outer(): x = 10 def inner(): x = 20 return x inner() return x print(outer())