R

Ram Sharma • 3.40K Points
Extraordinary

Q. What happens if a function has both *args and **kwargs?

Code:
def sample(*args, **kwargs):
print(args)
print(kwargs)

sample(1, 2, name='Alice', age=30)
  • (A) Only args will be printed
  • (B) Only kwargs will be printed
  • (C) Both args and kwargs will be printed
  • (D) SyntaxError
  • Correct Answer - Option(C)
  • Views: 3
  • Filed under category Python
  • Hashtags:

Explanation by: Ram Sharma
The function accepts both positional and keyword arguments, printing them separately.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.