ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
x = 5
def f(a, b=x * 2, *, c=x):
    return a + b + c
x = 100
print(f(1), f(1, c=x))
  1. A. 201 201
  2. B. 16 16
  3. C. 111 111
  4. D. 16 111

Correct answer: D. 16 111

Default expressions are evaluated once, when def executes (x was 5): b = 10, c = 5, giving 1+10+5 = 16. Passing c=x explicitly uses the current x = 100: 1+10+100 = 111.

More Python Programming questions

Exams that ask this topic