在Python中,“类型注释”和“类型提示”是同一回事吗?

时间:2019-11-24 23:48:58

标签: python type-hinting

在Python中,“类型注释”和“类型提示”是否相同?如果没有,它们之间有什么区别?

1 个答案:

答案 0 :(得分:1)

是的,它们都可以引用相同的事物集,即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]