Junior — Senior
Analysis of the add_element function in Python
livecode
Task condition
Analyze what the provided code snippet does, considering different ways of calling the function and the features of using mutable default arguments.
def add_element(new: list[str], src: list = []) -> list:
if isinstance(new, list):
src.extend(new)
else:
src.append(new)
return src
if __name__ == "__main__":
value1 = add_element("test")
print(value1)
value2 = add_element(["test2", "test3"])
print(value2)
value3 = add_element(new=["test4"], src=value2)
print(value3)
Describe what results will be output and why.