Use None as default parameter
def f(a, b = None):
if b == None:
b = []
b.append(a)
return b
print(f(1))
print(f(2))
print(f(3))
{% embed include file="src/examples/advanced-functions/none_as_default_parameter.out)
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
def f(a, b = None):
if b == None:
b = []
b.append(a)
return b
print(f(1))
print(f(2))
print(f(3))
{% embed include file="src/examples/advanced-functions/none_as_default_parameter.out)