The Mutable Default Trap

code Programming military_tech TACTICAL-4
info
You are not signed in.

You can read the task, take hints and check your answer — but nothing is saved. No XP, no skill points, and this task will not be marked complete.

assignment Your task

This function accumulates values between calls, which is almost never intended. Fix it.

```
def add_item(item, basket=[]):
basket.append(item)
return basket
```

What this proves: Recognise the shared-mutable-default bug, a classic Python interview question.

terminal Code / Terminal Workspace

lightbulb Progressive Hints

Need assistance? You can reveal sequential hints. Each hint applies a minor penalty to your score.

Hint #1 (-10 XP penalty)
Hint #2 (-20 XP penalty)

menu_book Full Solution Walkthrough

If you are completely stuck, you can unlock the full step-by-step walkthrough.