PL/Python

[Python] function docstring, 파이썬 좋은 문서 작성하기

SweetDev 2022. 1. 17. 14:56
print(print.__doc__)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)

Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

일단은 방법이 함수, 클래스, 모듈 다 다르다!!

 

함수의 docstring

def add_binary(a, b):
    '''
    Returns the sum of two decimal numbers in binary digits.

            Parameters:
                    a (int): A decimal integer
                    b (int): Another decimal integer

            Returns:
                    binary_sum (str): Binary string of the sum of a and b
    '''
    binary_sum = bin(a+b)[2:]
    return binary_sum


print(add_binary.__doc__)

 

라이브러리 추천

 

 

 

 

[출처]

https://www.programiz.com/python-programming/docstrings