问题
Is it possible to use type hinting when unpacking a tuple? I want to do this, but it results in a SyntaxError
:
from typing import Tuple
t: Tuple[int, int] = (1, 2)
a: int, b: int = t
# ^ SyntaxError: invalid syntax
回答1:
According to PEP-0526, you should annotate the types first, then do the unpacking
a: int
b: int
a, b = t
来源:https://stackoverflow.com/questions/52082939/type-hints-when-unpacking-a-tuple