ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
print(list(enumerate(["a", "b", "c"], start=5)))
- A. [(0, 'a'), (1, 'b'), (2, 'c')]
- B. [(5, 'a'), (6, 'b'), (7, 'c')]
- C. [('a', 5), ('b', 6), ('c', 7)]
- D. [(5, 'a'), (5, 'b'), (5, 'c')]
Correct answer: B. [(5, 'a'), (6, 'b'), (7, 'c')]
The start argument changes only the first counter value that pairs with each element, starting at 5 instead of the default 0: (5,'a'), (6,'b'), (7,'c').
More Python Programming questions
- What is printed? python from abc import ABC, abstractmethod class Shape(ABC): @abstractmethod def area(self): pass try: s = Shape() except…
- What is printed? python class Meta(type): def new(mcs, name, bases, ns): print("creating", name) return super().new(mcs, name, bases, ns)…
- What is printed? python class Vec: def init(self, x, y): self.x, self.y = x, y def radd(self, o): return Vec(self.x + o, self.y + o) def…
- What is printed? python class Idx: def index(self): return 3 l = [0, 1, 2, 3, 4, 5] print(l[Idx()])
- What is printed? python def f(a, b={"x": 1}): b["x"] += a return b print(f(1)) print(f(2))
- What is printed? python def f2(x, y, , z=None): if z is None: z = [] z.append(x + y) return z print(f2(1, 2)) print(f2(3, 4))