Type hints when unpacking a tuple?

梦想的初衷 提交于 2020-06-07 18:47:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!