ProgrammingHardInfosys pattern
What is printed?
What is printed?
def p(a, b, c=3):
return a, b, c
d = {"a": 1, "b": 2, "c": 10}
print(p(**d))- A. (1, 2, 3)
- B. (1, 2, 10)
- C. TypeError
- D. (1, 2, 10, {})
Correct answer: B. (1, 2, 10)
**d unpacks the dict into keyword arguments a=1, b=2, c=10, overriding the default c=3 since the dict supplies its own value for c.
More Python Programming questions
- What is printed? python def r(args): return sum(args) l = [1, 2, 3] print(r(l, l))
- What is printed? python import copy a = [[1, 2], [3, 4]] b = copy.deepcopy(a) b[0][0] = 99 print(a)
- What is printed? python import copy t = ([1, 2], [3, 4]) t2 = copy.deepcopy(t) t2[0].append(9) print(t)
- What is printed? python import copy a = [1, 2, 3] b = a.copy() c = list(a) d = a[:] e = copy.copy(a) a.append(4) print(b, c, d, e)
- What is printed? python try: print("a") except Exception: print("b") else: print("c") finally: print("d")
- What is printed? python def h(): try: x = 1 / 0 except ZeroDivisionError: return "caught" else: return "no error" finally: print("always")…