Programming · Flashcard

When is a default parameter value evaluated?

  • AOnce, when the function is defined — the same object is reused on every call
  • BOn every call that omits the argument — a fresh object is built each time
  • COn the first call only — later calls reuse the value cached at that point
  • DLazily on first use in the body — untouched defaults are never evaluated

Why this is the answer

Defaults are evaluated once at def time and stored on the function object — the root of the mutable-default gotcha. They're not rebuilt per call (the common wrong assumption), not tied to the first call, and not lazy.

Official docs
Study in Gnoseed →