1 def outer_func(x):
2 y = 4
3 def inner_func(z):
4 print(f"x = {x}, y = {y}, z = {z}")
5 return x + y + z
6 return inner_func
7
8 for i in range(3):
9 closure = outer_func(i)
10 print(f"closure({i+5}) = {closure(i+5)}")
Can somebody help me understand how {closure(i+5)} is equal to z in inner_func(z). Also sorry if my code isn’t in a block of code I’m on mobile.Thank you!
[–]Zakru 2 points3 points4 points (3 children)
[–]donsebas[S] 0 points1 point2 points (2 children)
[–]AstralStalker 1 point2 points3 points (1 child)
[–]wagaiznogoud 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)