在 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/