def append_to_lst(val, lst=[]):
lst.append(val)
return lst
print(append_to_lst(1))
print(append_to_lst(2))
print(append_to_lst(3, []))
Which of the following is the correct output of this program?
Solve 2+ Function Scope, Closures and Default Arguments previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.
None pattern for safe defaultsnonlocal keyword and state retentionWeight hint: Both topics are highly conceptual. Expect code-tracing questions where a small misunderstanding of evaluation time or scope leads to the wrong output.
In Python, default arguments are evaluated exactly once — when the def statement is executed, not when the function is called.
If the default value is a mutable object (like a list, dictionary, or set), that single object is shared across all function calls that use the default.
When Python reads a function definition, it evaluates the default expressions and stores them in the function object. Every time you call the function without providing that argument, Python passes the exact same object reference.
| Argument Type | Evaluated When | Behavior |
|---|---|---|
| Immutable (int, str, tuple) | Definition time | Safe. Reassignment creates a new local object. |
| Mutable (list, dict, set) | Definition time | Trap. Mutations affect the shared default object. |
Solve 2+ Function Scope, Closures and Default Arguments previous year questions for GATE DA with answers and detailed solutions. Free sample questions below.
Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.
Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.
Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.
We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.
Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.
Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.
Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.
No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.
Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.