gpt4 book ai didi

python - 在 Python 中, "type annotations"和 "type hints"是一回事吗?

转载 作者:行者123 更新时间:2023-12-04 10:58:23 29 4
gpt4 key购买 nike

在 Python 中,“类型注释”和“类型提示”是一回事吗?如果不是,它们之间有什么区别?

最佳答案

是的,它们都可以指同一组事物,即 the language feature of Python 3.5+ :

class Animal:
# *
name: str

# * * type annotations
def foo(self, bar: baz) -> quux:
...

有时还有像 Mypy 这样的工具支持的 Python-2 兼容的注释语法。 :
x = {6, 7}  # type: Set[int]

关于python - 在 Python 中, "type annotations"和 "type hints"是一回事吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59023552/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com