解压元组时输入提示? [英] Type hints when unpacking a tuple?

查看:79
本文介绍了解压元组时输入提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解包元组时是否可以使用类型提示?我想这样做,但结果是 SyntaxError:

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

推荐答案

根据 PEP-0526,你应该先注释类型,然后解包

According to PEP-0526, you should annotate the types first, then do the unpacking

a: int
b: int
a, b = t

这篇关于解压元组时输入提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆