The following code snippet which I came across, has output as 6,6,6,6
def multipliers():
return [lambda x : i * x for i in range(4)]
print([m(2) for m in multipliers()])
I don't understand why the output is 6,6,6,6
instead of 0,2,4,6
?
Can anyone please help me understand the internals of the above code as I am very new to Python. Thanks.