简体   繁体   中英

What exactly is a caller in python?

apologies if this question is too basic/obvious, but I can't find a reasonable answer after searching both here and through the data model docs.

My question is simply, what exactly is a caller in python 3? Is there a strict definition?

I know for example a function that calls another function is known as a caller. So:

def f1():
    pass
def f2():
    f1()

f2 is the caller of f1. But what about assignment statements?

x = f2()

Is xa caller of f2? Is it also a caller of f1? It's obviously been stated that the return statement at the end of a function definition returns a value to the caller, so I would assume in this case x is both a caller of f2 and f1, however I just want to check that there is no deeper/technical meaning to what a caller is?

I found this question I don't understand "return" in Python and what is a caller? , but I couldn't get much understanding.

The caller of a function is the unit of program code in which the call to the function occurred. This can be another function, a method (a specific type of function) or, in Python, the code in the "top level" of a python source code file -- generally referred to as a script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM