在Python中,你可以使用 `type()` 函数来查看返回值的类型。下面是一个简单的例子:
```python
def example_function(param1: int, param2: str) -> float:
return param1 + len(param2)
调用函数
result = example_function(10, "hello")
查看返回值的类型
print(type(result)) 输出:
如果你想查看函数定义时的预期返回类型,可以使用 `typing` 模块中的 `get_type_hints()` 函数:
```python
from typing import get_type_hints
def example_function(param1: int, param2: str) -> float:
return param1 + len(param2)
获取函数的类型提示
type_hints = get_type_hints(example_function)
查看返回值的类型提示
print(type_hints['return']) 输出:
请注意,`get_type_hints()` 函数在Python 3.5及以后的版本中可用。如果你使用的是更早的版本,你可能需要查看函数的文档字符串或使用其他方法来确定返回类型