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.

Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
Philip Kroup
  • 47
  • 1
  • 2
  • 8

1 Answers1

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)))
Dimitris Fasarakis Hilliard
  • 150,925
  • 31
  • 268
  • 253
  • 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 ??? – Philip Kroup Oct 18 '16 at 11:55