I'm struggling to understand Function closures properly. For example in the code below I am unclear as to how the function knows that in the statement times3(2)
that x=2
? Also, after reading documentations I still can't fully understand the purpose of closures.
def make_multiplier_of(n):
def multiplier(x):
return x * n
return multiplier
times3 = make_multiplier_of(3)
times3(2) #How does the function know that x=2 here?
Thanks a lot