---
title: "Why Does My Python Function Keep Tags From an Earlier Call?"  
description: "Why Does My Python Function Keep Tags From an Earlier Call?"  
author: "Ruslan Galiev"  
published: 2026-10-18  
canonical: https://answers.mindstick.com/qa/117867/why-does-my-python-function-keep-tags-from-an-earlier-call  
category: "Mix Category"  
tags: ["Python", "functions", "Mutable Objects", "Debugging"]  
reading_time: 1 minute  

---

# Why Does My Python Function Keep Tags From an Earlier Call?

I wrote a small helper that adds a tag to a list. If no list is supplied, I expected it to start with an empty one each time.

```python
def add_tag(tag, tags=[]):
    # Add the new tag to the supplied list.
    tags.append(tag)
    return tags

# These calls are intended to create independent lists.
print(add_tag("python"))
print(add_tag("seo"))
```

The output is:

- First call: `['python']`
- Second call: `['python', 'seo']`

Why is the second call using the earlier list? Is this specific to **mutable default arguments**, or can it happen with defaults such as strings and numbers too?

What is the usual way to give each omitted argument a fresh list while still allowing callers to pass an existing list that the function deliberately modifies?


---

Original Source: https://answers.mindstick.com/qa/117867/why-does-my-python-function-keep-tags-from-an-earlier-call

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
