找出可变默认值里的 bug

来自 函数
Python 3.14 入门 3分钟 找出 1处问题

找出这个标签辅助函数中的状态泄漏。

Python
def add_tag(tag: str, tags: list[str] = []) -> list[str]:
    tags.append(tag)
    return tags

first = add_tag("urgent")
second = add_tag("gift")
print(first, second)
在试验场中打开
报告错误