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"))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.