google风格docstring中同时返回多个值(一个元组)的情况

白天在statckoverflow上看到的一种格式(原链接不找了):

def say_hello(name='world', age=2):
    """say hello to someone

    Say hello to the people who have the name you given.

    Args:
        name (str): The people's name you want to greet. world by default.
    
    Returns:
        tuple: tuple contains:
            name (str): name
            age (int): age

    """
    print(f"Hello {name}")
    return name, age

生成文档的效果如下:
在这里插入图片描述
可以看到两个参数被放到一行了,不知道还有没有什么更好的方案,发现了再更新。

破案了破案了。
中间加换行符就可以了:

    Returns:
        tuple: tuple contains:
            name (str): name \n
            age (int): age

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Crazy_zh/article/details/111706387