【发布时间】:2014-01-08 20:05:39
【问题描述】:
你可以在python 3中使用function annotations来表示参数和返回值的类型,如下所示:
def myfunction(name: str, age: int) -> str:
return name + str(age) #usefulfunction
但是,如果您正在编写一个期望函数作为参数或返回一个参数的函数呢?
我意识到您可以为注释编写任何有效的表达式,因此我可以将“函数”编写为字符串,但这是最好/唯一的方法吗?有没有像内置类型int/float/str/list/dict 等的东西?我知道callable,但我想知道是否还有其他内容。
【问题讨论】:
标签: python function python-3.x annotations