LearnFrenzy
Sign in Take a free test

Functions · Predict the Output · Question 10

Unpacking a list and a dict into a call Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 10 Back to Exercise

What is the output of the following Python program?

main.py
def volume(l, w, h=1):
    return l * w * h

dims = [2, 3]
opts = {"h": 4}
print(volume(*dims), volume(*dims, **opts), volume(**{"l": 1, "w": 5}))
  • A 6 6 5
  • B 24 24 5
  • C 6 24 5 Correct
  • D TypeError
Correct Answer: Option C

*dims passes 2 and 3; **opts passes h=4; the last call passes l and w by keyword with h defaulting to 1.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links