Question discussion

What is the output of the following Python code?def f(a, *b, **c): return (a, b, c) print(f(1, 2, 3, x=4))

2113Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following Python code?

def f(a, *b, **c):
    return (a, b, c)
print(f(1, 2, 3, x=4))
  • A(1, (2,), {'x': 4})
  • B(1, (2, 3), (4,))
  • C(1, (2, 3), {'x': 4})
  • DAn error is raised
Correct answer: C

Explanation

The extra positional arguments are collected into the tuple b = (2, 3) and the keyword argument into the dictionary c = {'x': 4}.

Discussion 0

Nobody has replied yet. Start the discussion!