python中的_doc_是什么
生活随笔
收集整理的這篇文章主要介紹了
python中的_doc_是什么
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
文檔字符串。注意,是 __doc__ ,
前后各兩個(gè)下劃線。
一般而言,是對函數(shù)/方法/模塊所實(shí)現(xiàn)功能的簡單描述。但當(dāng)指向具體對象時(shí),會(huì)顯示此對象從屬的類型的構(gòu)造函數(shù)的文檔字符串。(示例見以下 a.__doc__)
>>> str.__doc__
"str(string[, encoding[, errors]]) -> str\n\nCreate a new string object from the given encoded string.\nencoding defaults to the current default string encoding.\nerrors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."
>>> import math
>>> math.__doc__
'This module is always available.? It provides access to the\nmathematical functions defined by the C standard.'
>>> a = [1]
>>> a.count.__doc__
'L.count(value) -> integer -- return number of occurrences of value'
>>> a.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"
為自定義的函數(shù)創(chuàng)建 __doc__ 的方法示例:
>>> def func():
??? """Here's a doc string"""
??? pass
>>> func.__doc__
"Here's a doc string"
一般而言,是對函數(shù)/方法/模塊所實(shí)現(xiàn)功能的簡單描述。但當(dāng)指向具體對象時(shí),會(huì)顯示此對象從屬的類型的構(gòu)造函數(shù)的文檔字符串。(示例見以下 a.__doc__)
>>> str.__doc__
"str(string[, encoding[, errors]]) -> str\n\nCreate a new string object from the given encoded string.\nencoding defaults to the current default string encoding.\nerrors can be 'strict', 'replace' or 'ignore' and defaults to 'strict'."
>>> import math
>>> math.__doc__
'This module is always available.? It provides access to the\nmathematical functions defined by the C standard.'
>>> a = [1]
>>> a.count.__doc__
'L.count(value) -> integer -- return number of occurrences of value'
>>> a.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"
為自定義的函數(shù)創(chuàng)建 __doc__ 的方法示例:
>>> def func():
??? """Here's a doc string"""
??? pass
>>> func.__doc__
"Here's a doc string"
總結(jié)
以上是生活随笔為你收集整理的python中的_doc_是什么的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JAVA项目打成可执行jar包
- 下一篇: MATLAB时间序列的排序函数