0

This is my first question in stack overflow! sorry for my bad English :)

I'm newbie in python and something weird happened to me when I was tried to define a function, that returning other functions. Here is my first code:

def hello_function():
    def say_hi():
        return "Hi"
    return say_hi
print(hello_function())

The output is: <function hello_function.<locals>.say_hi at 0x000001F9B2C3CE50>

but when i Assigned hello_function() to hello variable and call the hello(), the output is correct:

def hello_function():
    def say_hi():
        return "Hi"
    return say_hi
hello = hello_function()
hello()

output: 'Hi'

BiZzed
  • 1
  • 3
  • That is… correct. You're returning a function. So, when printing that function, you'll see a function object. To get the return value of a function, you need to call it. – deceze Sep 29 '21 at 08:35

0 Answers0