Setting the docstring to an expression inside def

后端 未结 4 1795
南笙
南笙 2021-01-19 07:36

I would like to set the func_doc (as an expression) within def.

def f():
    \'\'\'My function help\'\'\' #Set the         


        
4条回答
  •  醉话见心
    2021-01-19 07:58

    You can modify the __doc__ attribute of the function at runtime:

    >>> def what():
    ...    """docstring"""
    ...    what.__doc__ += " x"
    ...    print what.__doc__
    ... 
    >>> what()
    docstring x
    >>> what()
    docstring x x
    >>> what()
    docstring x x x
    >>> what()
    docstring x x x x
    

提交回复
热议问题