The output is the function object itself. The word function
is the type
of the function object you printed. The part string_function
is the name of the object. The numbers are the address of the function object in memory.
Everything in Python is a first class object, including functions and classes. Functions even have their own function
type in Python (which you can discover by just doing type(myfunction)
)- just like 100
is an int
, 'Hello World'
is a str
, True
is a bool
, or myfancyobject
is a MyFancyClass
instance.
You can, for example, pass functions (or even classes themselves, which are of the type type
) into other functions:
def increment(x): return x + 1
def sayHiBefore(func, *args, **kwargs):
print('Hi')
return func(*args, **kwargs)
print(sayHiBefore(increment, 1))
This is obviously a pretty contrived illustration, but being able to pass around functions this way turns out to be extremely useful. Decorators are a good example of something useful you can do with this ability. Google "python decorators" to find out more about them.
Another thing you can do with objects is give them attributes! You can even do things like this:
increment.a = 1
Pretty much anything you can do to an object, you can do to a function (including print
them, as in your example); they are objects.