When the function with a default value a = []
, i.e empty list, is called without passing a value to a, the list should be empty.
def func1(x, a = []):
if x == 5:
print(a)
return
x += 1
a.append(x)
func1(x)
func1(1)
At x == 5, it should return [5]. Another case:
def func1(a = []):
a.append(2)
return a
print(func1())
print(func1())
print(func1())
Output:
[2]
[2, 2]
[2, 2, 2]
The output should be same each time func1 is called.