0

when i run the code i get a memory location as an output

<function at 0x00000200FF8A5E50>

val = (lambda colmns:(colmns.max + colmns.min)/2
print(val)
4
  • 3
    You need to actually use the lambda. If you try to print it directly, you will get the address of where the lambda code lives in memory. Commented Jul 21, 2022 at 22:54
  • Right. Assuming you have an array, do print(val(array)). Commented Jul 21, 2022 at 22:57
  • val is a function object, it isn't a "memory address", when you print a function object, that is how it is represented, just like any function, try def foo(): return 42 then print(foo) Commented Jul 21, 2022 at 23:05
  • Why did you expect a different output? Commented Jul 21, 2022 at 23:05

1 Answer 1

0

A lambda is just an anonymous function object and that's why it prints that way. In fact, as soon as you assign it to a variable... then why have a lambda in the first place? Might as well do

def foo(colmns): 
    return (colmns.max + colmns.min)/2

And then it wouldn't be too surprising that print(foo) is <function 0x...>.

Sign up to request clarification or add additional context in comments.

1 Comment

@hghebrem - what are you talking about? The thing you seemed to have missed is that lambda creates a function object, and that's what I illustrated with the def. But I still needed to wrap that back specifically to the question about where "<function at 0x00000200FF8A5E50>" comes from. When you see it as a def I didn't think there would be any question about why is printed as a "function".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.