Mutating vs Rebinding the Default
Two helpers, each with a list default:
def accumulate(x, bucket=[]):
bucket.append(x)
return bucket
def replace(x, bucket=[]):
bucket = bucket + [x]
return bucket
print(accumulate(1))
print(accumulate(2))
print(replace(1))
print(replace(2))
What gets printed, in order?
Sign in to answer questions and track your progress
Sign In