← 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?
- A.Lists are not allowed as defaults
- B.The same list is shared across calls, so it keeps growing
- C.It makes the function slower
- 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 →