LearnFrenzy
Sign in Take a free test

Functions · Predict the Output · Question 9

A default taken from a variable Answer, explanation & discussion

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

What is the output of the following Python program?

main.py
i = 5
def f(arg=i):
    return arg

i = 6
print(f(), f(7))
  • A 6 7
  • B 5 5
  • C 5 7 Correct
  • D 6 6
Correct Answer: Option C

The default is evaluated when def runs, while i is still 5. Changing i later does not affect it.

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