ProgrammingHardCapgemini · Python
What is printed?
What is printed?
a, *b, c = range(5) x, (y, *z) = 1, 'hey' print(a, b, c, x, y, z)
- A. 0 [1, 2, 3] 4 1 h 'ey'
- B. 0 (1, 2, 3) 4 1 h ['e', 'y']
- C. 0 [1, 2, 3] 4 1 h ('e', 'y')
- D. 0 [1, 2, 3] 4 1 h ['e', 'y']
Correct answer: D. 0 [1, 2, 3] 4 1 h ['e', 'y']
A starred target always collects a list, even when the source is a string or tuple.
More Python Programming questions
- What is printed? python from collections import Counter c = Counter('mississippi') print(c.mostcommon(2), c['z'], sorted(c.items())[:2])
- What is printed? python pts = [(2, 1), (1, 5), (2, 0), (1, 2)] print(sorted(pts, key=lambda p: (-p[0], p[1])), max(pts, key=lambda p: p[1]))
- What is printed? python import copy a = {'k': [1, 2]} b = a.copy() c = copy.deepcopy(a) a['k'].append(3) a['j'] = 0 print(b, c)
- What is printed? python m = map(lambda x: x 2, [1, 2, 3]) print(list(m), list(m), sum(map(int, '123')))
- What is printed? python class P: def init(self, v): self.v = v def eq(self, o): return self.v == o.v try: s = {P(1), P(1)} print(len(s))…
- What is printed? python fs = [lambda x, i=i: x i for i in range(3)] gs = [lambda x: x i for i in range(3)] print([f(2) for f in fs], [g(2)…