🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Python Functions: all 15 questions

Quiz: Python Functions · Question 5 of 15

Why is def f(items=[]) risky?

Why is def f(items=[]) risky?

  1. A.Lists are not allowed as defaults
  2. B.The same list is shared across calls, so it keeps growing
  3. C.It makes the function slower
  4. D.It causes a SyntaxError
Answer & explanation

Correct answer: The same list is shared across calls, so it keeps growing

Default values are created once, when the function is defined, so the same list is reused.

Can you get the rest right without peeking?

Take the timed Quiz: Python Functions quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →