使用typing.Tuple
:
from typing import Tuple
def func() -> Tuple[str, str]:
return 'a', 'b'
这是合适的,因为从概念上讲,您实际上返回了一个包含这些值的tuple
.注:
print(type(func()))
输出:
<class 'tuple'>
除了空的tuple
(()
)和parentheses are not necessary to define a tuple
之外,这意味着'a', 'b'
被创建为tuple
,而不是由return
语句收集成一个单独的值.