-
DocstringProgramming Language/Python 2023. 12. 14. 01:00
docstring은 코드 내에서 문서화 하기 위한 문자열 리터럴이다. module, class, function or method 을 문서화하는데 쓰이며 주석 같은 역할을 한다.
''' 또는 """ 로 열고 닫으면 되며 반드시 맨 첫 줄에 써야 한다.
다음과 같이 쓰면 된다.
def f(): '''test''' a=1 f.__doc__ 'test'docstring 내용을 외부에서 확인하고 싶다면 __doc__를 통해 확인할 수 있다.
docstring style도 여러가지가 있기 때문에 다음의 사이트에서 Python Docstring Formats 문단을 참고하면 된다.
https://www.datacamp.com/tutorial/docstrings-python
'Programming Language > Python' 카테고리의 다른 글
Closure, First Class Object (0) 2024.04.11 The Zen of Python (0) 2024.04.02 Nested function, Nonlocal, Global (0) 2024.04.02 Boolean 더하기 (0) 2023.10.15 string 함수 split(), split(' ') 차이점 (1) 2023.10.13