Sobes.tech
Junior — Senior

Function behavior with a mutable default argument

livecode

Task condition

What will be the output when the given code is executed? Possible answers:

  • [10] [10, 10] [10, 10, 10]
  • Error will occur
  • [10] [10] [10]
  • [10, 10, 10] [10, 10, 10] [10, 10, 10]
  • [] [10] [10, 10]
def func(data=[]):
    data.append(10)
    return data
print(func())
print(func())
print(func())
Function behavior with a mutable default argument… - sobes.tech