简体   繁体   中英

TypeError: f3() takes 2 positional arguments but 3 were given

This is the question from my exam, I cannot figure out why it ends with TypeError.

    def f1(a,b,f):
        return f(a,b, f)

    def f2(a,b, f):
        return f(a,b,f3)

    def f3(a,b):
        return f3(a,b)

    f1(1,2,f2)

Crazy exam problem.

Best is just to work it out, calling the function and replacing the parameters in the result as you go:

f1(1, 2, f2) =
f2(1, 2, f2) =
f2(1, 2, f3) =
f3(1, 2, f3)

which is an attempt to call f3 with three arguments, but the definition of f3 says it only takes two parameters.

Good news is that the error message was correct, even though the call was made through a parameter, so yes it can be confusing.

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