Reputation: 454
In Python, we can specify the return type of function as
def foo() -> int:
some_int = get_some_int()
return some_int
How to specify return types when returning multiple values? For example, how would one specify return types for the following function?
def bar(): # -> ?
some_float = get_some_float()
some_int = get_some_int()
return some_float,some_int
Upvotes: 6
Views: 2018
Reputation: 11992
You are only returning one type whcih is a tuple which then contains your float and your int. but the function its self returns a tuple. You can annotate this with type hint like.
from typing import Tuple
def bar() -> Tuple[float, int]:
some_float = get_some_float()
some_int = get_some_int()
return some_float,some_int
Upvotes: 10