I'm learning about higher-order functions, specifically lambda functions in Python. I understand lambda functions to an extent, but a little confused about this lambda higher-order function example.
Why am I getting 6 as the output, I'm just trying to understand this mathematically
>>> high_ord_func = lambda x, func: x + func(x)
>>> high_ord_func(2, lambda x: x * x)
6
I got this problem from Real Python article. Please, I just want to make sense of this, thank you
func
argument ofhigh_ord_func
is? If you writesq = lambda x: x * x
, what do you thinksq(2)
will be?print()
to see what code is doing.high_ord_func(2, lambda y: y * y)
. The functionality and result are unchanged.