What is the output of the following? “`python def make_adder(n): return lambda x: x + n adders = [make_adder(i) for i in range(3)] print(adders[0](10), adders[1](10), adders[2](10)) “`

Python Developer Hard

Python Developer — Hard

What is the output of the following? “`python def make_adder(n): return lambda x: x + n adders = [make_adder(i) for i in range(3)] print(adders[0](10), adders[1](10), adders[2](10)) “`

Key points

  • Each lambda function in the list adds a different value to 10
  • The lambda functions are created using a higher-order function
  • The `adders` list stores multiple lambda functions
  • The output is determined by the values of `i` in the `range(3)` loop

Ready to go further?

Related questions