What does the following code output? def make_adder(n): return lambda x: x + n add5 = make_adder(5) print(add5(3), add5(10))

Python Developer Medium

Python Developer — Medium

What does the following code output? def make_adder(n): return lambda x: x + n add5 = make_adder(5) print(add5(3), add5(10))

Key points

  • The lambda function adds the value of n to its input
  • The add5 function adds 5 to any input
  • The output of add5(3) is 8, and add5(10) is 15

Ready to go further?

Related questions