Skip to content Skip to sidebar Skip to footer

Function Annotation In Python 3 Get "name Not Defined" Error

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:str): return x + ' retu

Solution 1:

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

deffa(func: 'function', *args):

Solution 2:

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

deffa(func: 'function', *args):

Besides what @johnrsharpe says you can also include the following line at the top of your python script if you don't want to qoute the name function

# from __future__ imports must occur at the beginning of the file. DO NOT CHANGE!from __future__ import annotations

Solution 3:

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

fa(function="Newton")

Post a Comment for "Function Annotation In Python 3 Get "name Not Defined" Error"