__doc__

将文档写在程序里,是LISP中的一个特色,Python也借鉴过。每个函数都是一个对象,每个函数对象都是有一个__doc__的属性,函数语句中,如果第一个表达式是一个string,这个函数的__doc__就是这个string,否则__doc__是None。

 

[python] view plaincopy
 
  1. >>> def testfun():
  2. """
  3. this function do nothing , just demostrate the use of the doc string .
  4. """
  5. pass
  6. >>> testfun.__doc__
  7. '\nthis function do nothing , just demostrate the use of the doc string .\n'
  8. >>> #pass 语句是空语句,什么也不干,就像C语言中的{} , 通过显示__doc__,我们可以查看一些内部函数的帮助信息
  9. >>> " ".join.__doc__
  10. 'S.join(iterable) -> str\n\nReturn a string which is the concatenation of the strings in the\niterable. The separator between elements is S.'
  11. >>>
[python] view plain copy
 
  1. >>> def testfun():  
  2.     """ 
  3. this function do nothing , just demostrate the use of the doc string . 
  4. """  
  5.     pass  
  6.   
  7. >>> testfun.__doc__  
  8. '\nthis function do nothing , just demostrate the use of the doc string .\n'  
  9. >>> #pass 语句是空语句,什么也不干,就像C语言中的{} , 通过显示__doc__,我们可以查看一些内部函数的帮助信息  
  10. >>> " ".join.__doc__  
  11. 'S.join(iterable) -> str\n\nReturn a string which is the concatenation of the strings in the\niterable.  The separator between elements is S.'  
  12. >>>   

posted on 2016-05-26 16:20  竹雨阑珊1  阅读(230)  评论(0编辑  收藏  举报

导航