Ask whether this function of python can be realized.

I want to have a function that is output when it is executed separately, but returns the output when called by other functions, but does not output
for example, code similar to the following when directly executed:
def foo:

print 111

but it is executed when called by another function:
def foo:

return 111

This is about the meaning of

. It is not very good at expressing it. To put it bluntly, it is an output function, but when called by other functions, it only returns the content of the calling function and does not output

.
Jun.23,2021

print foo ()


How can

be called by others?

class foo:
    def __str__(self):
        return 'print'

    def __call__(self, *args, **kwargs):
        print('111111')
a = foo()
a()
print(a)
Menu