🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Reviewing AI Code: all 10 questions

Quiz: Reviewing AI Code · Question 6 of 10

What does this print? (code)

What does this print?

def add_score(score, scores=None):
    scores = [] if scores is None else scores
    scores.append(score)
    return scores

add_score(90)
print(add_score(75))
  1. A.[90, 75]
  2. B.[75]
  3. C.[90]
  4. D.None
Answer & explanation

Correct answer: [75]

With None as the default, every call gets a fresh list.

Can you get the rest right without peeking?

Take the timed Quiz: Reviewing AI Code quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →