Function annotation in python 3 get “name not defined” error

前端 未结 2 1338
长发绾君心
长发绾君心 2021-01-22 08:37

I am trying to use python3 type annotation features.

Here is some toy functions without annotation:

def fa(func, *args):
    return func(*args)
def fb(x:         


        
相关标签:
2条回答
  • 2021-01-22 09:19

    As the error message tells you, the name function isn't defined. If you want to hint as a function, put it in quotes:

    def fa(func: 'function', *args):
    
    0 讨论(0)
  • 2021-01-22 09:20

    Because you define a variable in function parameters,but that parameter is not exist out of function.You have to write

    fa(function="Newton")

    0 讨论(0)
提交回复
热议问题