Python之规范化编程

Python规范化编程:

文档字符串

文档字符串是在函数的开头加上一系列的说明性文字,来帮助后续的开发者快速了解函数的解释。查看方式有两种:
  • print functionname.__doc__
  • help(functionname)
def add(a,b):
    '''
    get sum of first and second input
    :param a: first input
    :param b: sencond input
    :return: sum of first and second input
    '''
    return a + b
help(add)
print(add.__doc__)
运行结果如下
Help on function add in module __main__:

add(a, b)
    get sum of first and second input
    :param a: first input
    :param b: sencond input
    :return: sum of first and second input


    get sum of first and second input
    :param a: first input
    :param b: sencond input
    :return: sum of first and second input




猜你喜欢

转载自blog.csdn.net/iee2285/article/details/79282652