Type hints in namedtuple

前端 未结 2 1583
误落风尘
误落风尘 2020-12-04 18:54

Consider following piece of code:

from collections import namedtuple
point = namedtuple(\"Point\", (\"x:int\", \"y:int\"))

The Code above i

2条回答
  •  一向
    一向 (楼主)
    2020-12-04 19:02

    You can use typing.NamedTuple

    From the docs

    Typed version of namedtuple.

    >>> import typing
    >>> Point = typing.NamedTuple("Point", [('x', int), ('y', int)])
    

    This is present only in Python 3.5 onwards

提交回复
热议问题