python 文档资源 dir __doc__

来源:互联网 发布:微信红包的随机算法 编辑:程序博客网 时间:2024/06/06 09:35

形式:   角色

#注释 文档中的文档

dir 函数 对象中可用属性的列表

文档字符串:__doc__ 附加在对象上的文件中的文档

PyDoc:help函数 对象的交互帮助

PyDoc:HTML报表 浏览器中的模块文档

>>> import  sys
>>> dir(sys)
['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', ...........omited']
>>> sys.__doc__
"This module provides access to some objects used or maintained by the\ninterpreter and to functions that interact strongly with the interpreter.\n\nDynamic objects:\n\nargv -- command line arguments; argv[0] is the script pathname if known\npath ,....................................omited"

使用dir查看内置对象类型提供了哪些属性,可以运行dir并且传入所需要类型的变量,例如查看列表的属性传入空对象即可

>>> dir([])
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

__doc__使用

>>> def squre(data):
"""the squre is a function that.......
"""
return data**2


>>> squre.__doc__
'the squre is a function that.......\n\t'

help的使用

>>> help(sys.getrefcount)
Help on built-in function getrefcount in module sys:


getrefcount(...)
    getrefcount(object) -> integer
    
    Return the reference count of object.  The count returned is generally
    one higher than you might expect, because it includes the (temporary)
    reference as an argument to getrefcount().


0 0
原创粉丝点击