ProgrammingModerateAccenture · Capgemini pattern
What is printed?
What is printed?
print(" ".join(i * ch for i, ch in enumerate("xyz", 1)), list(enumerate("ab"))[-1])- A. x yy zzz ('b', 1)
- B. xyz xyz xyz (1, 'b')
- C. x yy zzz (1, 'b')
- D. xx yyy zzzz (2, 'b')
Correct answer: C. x yy zzz (1, 'b')
enumerate("xyz", 1) starts counting at 1, giving (1, 'x'), (2, 'y'), (3, 'z'); int * str repeats the string, so the words are x, yy, zzz. Without a start argument counting begins at 0, and each item is an (index, value) tuple, so the last item of enumerate("ab") is (1, 'b'), not ('b', 1).
More Python Programming questions
- What is printed? python nums = list(range(10)) print(nums[8:2:-2], nums[-3:], nums[2:8:-1])
- What is printed? python print(min([3, -4, 2], key=lambda v: v v), max({"a": 3, "b": 1}), max("abc", "b", key=len))
- What is printed? python class Box: def len(self): return 0 b = Box() print(bool(b), "yes" if b else "no", len([b, b]))
- What is printed? python a = [3, 1, 4, 1, 5] a.insert(-1, 9) print(a, a.index(1), a.pop(), a.count(1))
- What is printed? python def g(): print("start", end=" ") yield 1 print("mid", end=" ") yield 2 it = g() print("made", end=" ")…
- What is printed? python x = 1 def f(flag): if flag: x = 2 return x print(f(True), end=" ") try: print(f(False)) except UnboundLocalError…