docstring(文档字符串):在编程中(尤指 Python),指写在模块、类、函数等对象开头的一段字符串,用来说明其用途、参数、返回值与用法,常被文档工具自动提取生成说明文档。
/ˈdɑːkˌstrɪŋ/
A good docstring explains what the function does.
一个好的文档字符串能解释这个函数的作用。
Before publishing the library, she rewrote the docstrings to include clear examples and edge cases so new users could understand the API quickly.
在发布这个库之前,她重写了文档字符串,补充了清晰的示例和边界情况,让新用户能更快理解该 API。
docstring 是 documentation(文档)+ string(字符串)的合成词,主要流行于编程语境,尤其与 Python 社区的编码与文档规范密切相关;含义直观:用“字符串”来写“文档说明”。