How do I use function annotations to indicate whether a function requires a function as an argument or returns a function?

You can use function annotations in Python 3 to indicate the type and return value of parameters, as follows:

def myfunction(name: str,age: int) -> str:
    return name + str(age) #usefulfunction

But what if you're writing a function that expects a function as a parameter, or returns a function?

I realize that you can write any valid expression for comments, so I can write "function" as a string, but is this the best / only way? Are there built-in types like int / float / str / list / dict? I know it's redeemable, but I wonder if there's anything else

Solution

No style defined for annotation Use label, types Functiontype or string

PS: pylable is not available in Python 3.0 and 3.1

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>