1

Here's the code:

def my_func(f, arg):
  return f(arg)

print((lambda x: 2*x*x, (5)))

>>>(<function <lambda> at 0x10207b9d8>, 5)

How to solve the error, and can some please explain in a clear language what exactly that error means.

3
  • What were you trying to do? Did you want to apply the lambda function to 5? Oct 18, 2016 at 1:51
  • What error is it that you're receiving? Oct 18, 2016 at 1:54
  • You're not calling 'my_func' in the print statement. Oct 18, 2016 at 1:56

1 Answer 1

4

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)))
1
  • Ok thank you. But I had many other functions that gave me the message. I just wanted to know and understand what's the general meaning of <function at 0x ...> ??? Oct 18, 2016 at 11:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.