Question #114

What is the output of the following code snippet?
def foo(a=[]):
    return a


The list keeps getting longer and longer. The function keeps using the same object a as a default argument. The first time the function is executed, a does not exist: it is created as an empty list. The second time the function is executed, a already exists: 5 is appended to it. (

Comment on Disqus:

Comment on Twitter:

Question difficulty: πŸ”΅πŸ”΅πŸ”΅πŸ”΅πŸ”΅

Similar questions: