Here\'s the code:
def my_func(f, arg):
return f(arg)
print((lambda x: 2*x*x, (5)))
>>>( at 0x10207b9d8>, 5)
There is no error; you simply supplied two arguments to print
, the lambda x: 2*x*x
and 5
. You're not calling your anonymous function rather, just passing it to print
.
print
will then call the objects __str__
method which returns what you see:
>>> str(lambda x: 2*x*x) # similarly for '5'
'<function <lambda> at 0x7fd4ec5f0048>'
Instead, fix your parenthesis to actually call the lambda with the 5
passed as the value for x
:
print((lambda x: 2*x*x)(5))
which prints out 50
.
What's the general meaning of
<function at 0x ...>
?
That's simply the way Python has chosen to represent function objects when printed. Their str
takes the name of the function and the hex
of the id
of the function and prints it out. E.g:
def foo(): pass
print(foo) # <function foo at 0x7fd4ec5dfe18>
Is created by returning the string:
"<function {0} at {1}>".format(foo.__name__, hex(id(foo)))