The quiz where the difficulty automagically adapts to the player's Python knowledge
This is a question page. You can use this page to bookmark a question. Start a new quiz!
Question #114
def foo(a=[]):
a.append(5)
return a
foo()
foo()
foo()
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. (effbot.org/zone/default-values.htm)
What is the output of the following code snippet?
— The Python Quiz (@thepythonquiz) July 10, 2020
def foo(a=[]):
a.append(5)
return a
foo()
foo()
foo()
[5]
[5,5]
[5,5,5]
[5]
[5]
[5]#python #python3 #pythonprogramming #learnpython
Question difficulty: π΅π΅π΅π΅π΅
Similar questions: