VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
Easy10 XPfunctionsbugs

Why does a Python function keep data between calls?

A helper is called twice in a web server. What does the second call print?

def add_tag(tag, tags=[]):
    tags.append(tag)
    return tags

add_tag("python")
print(add_tag("sql"))
Stuck? Show the solution

Answer: B. ['python', 'sql']

The default list is created once, when def runs, and every call that relies on it shares that same list. Use tags=None and create the list inside the function.

Learn the idea behind itFunctions — Arguments, Scope and the Call Stack