Adding docstrings to namedtuples?

前端 未结 10 1525
死守一世寂寞
死守一世寂寞 2020-12-08 01:52

Is it possible to add a documentation string to a namedtuple in an easy manner?

I tried

from collections import namedtuple

Point = namedtuple(\"Poin         


        
10条回答
  •  太阳男子
    2020-12-08 02:09

    In Python 3.6+ you can use:

    class Point(NamedTuple):
        """
        A point in 2D space
        """
        x: float
        y: float
    

提交回复
热议问题