0

This is my program in which it has a function named "spam" containing default arguments in which it has an empty list.

def spam(n, l=[]):
    l.append(n)
    return l

x=spam(42)
print x
y=spam(33)
print y
z=spam(9999)
print z

output:

[42]
[42, 33]
[42, 33, 9999]

l[] is an empty list right which is a default argument. why is it not taking empty list every time when spam function is called?

Ysh
  • 803
  • 1
  • 9
  • 13

0 Answers0