Docstring for variable

前端 未结 9 1909
予麋鹿
予麋鹿 2021-01-31 13:35

Is it posible to use docstring for plain variable? For example I have module called t

def f():
    \"\"\"f\"\"\"

l = lambda x: x
\"\"\"l\"\"\"
         


        
9条回答
  •  别那么骄傲
    2021-01-31 14:09

    Properties can have docstrings! This covers the most common use case of documenting instance variables.

    class A:
        def __init__(self):
            self._x = 22
    
        @property
        def x(self):
            "document x"
            return self._x
    
        @x.setter
        def x(self, value):
            self._x = value
    
    A.x.__doc__
    

提交回复
热议问题