Python 函数的返回类型是函数?


def func(input: str) -> int: _another_func(input)
// ...
// returns some int
def _another_func(input: str) -> None
if (input == "abc"):
raise Exception

在这种情况下,返回类型作为函数是什么意思,该函数不依赖于实际返回结果,而是依赖于父函数的输入?当_another_func()得到运行?

它只是显示了在这种情况下应该返回哪种数据类型int。_another_func(input)应该在新行。但如果你尝试返回另一种数据类型,它也能工作。这只是为了使维护/代码审查/生活更容易。

最新更新