Python的一个优势是有着大量自带和在线的模块(module)资源,可以提供丰富的功能,在使用这些模块的时候,如果每次都去网站找在线文档会过于浪费时间,因此,我们可以使用IDLE里边自带的查看帮助功能,可以在编辑时不中断地迅速找到所需要模块和函数的使用方法。

通用帮助函数help

在Python命令行中键入help(), 就可以看到:

>>> help()Welcome to Python 3.5's help utility!If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/3.5/tutorial/.Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

进入help帮助文档界面, 根据屏幕提示可以继续键入相应的关键词进行查询, 继续键入modules可以列出当前所有安装的模块:

help> modulesPlease wait a moment while I gather a list of all available modules...AutoComplete        _sqlite3            fnmatch             pymsgbox
AutoCompleteWindow  _sre                formatter           pyparsing
AutoExpand          _ssl                fractions           pyperclip
Bindings            _stat               ftplib              pyscreeze
CallTipWindow       _string             functools           pytweening
CallTips            _strptime           gc                  queue
......Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

可以继续键入相应的模块名称得到该模块的帮助信息. 这是Python通用的查询帮助, 可以查询到几乎所有的帮助文档, 但我们很多时候不需要这样层级式的向下查询,接下来介绍如何直接查询特定的模块 模块函数 的帮助信息.

模块帮助查询

查看.py结尾的普通模块help(module_name)

例如查询math模块的使用方法,可以如下操作:

>>> import math
>>> help(math)
Help on built-in module math:NAMEmathDESCRIPTIONThis module is always available.  It provides access to themathematical functions defined by the C standard.FUNCTIONSacos(...)acos(x)Return the arc cosine (measured in radians) of x.acosh(...)acosh(x)Return the inverse hyperbolic cosine of x.fabs(...)fabs(x)Return the absolute value of the float x.factorial(...)factorial(x) -> IntegralFind x!. Raise a ValueError if x is negative or non-integral.
DATAe = 2.718281828459045inf = infnan = nanpi = 3.141592653589793FILE(built-in)

使用help(module_name)时首先需要import该模块, 不先进行导入可能会出出错

查看內间模块sys.builtin_module_name

>>> import sys
>>> sys.builtin_module_names
('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_collections', '_csv', '_datetime', '_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5',  'zipimport', 'zlib')

需要导入sys模块. 这里列举的一般是自带的使用C/C++编译链接的模块

查询函数信息

查看模块下所有函数dir(module_name)

如我们需要列举出math模块下所有的函数名称

>>> dir(math)
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

同样需要先导入模块

查看模块下特定函数信息help(module_name.func_name)

>>> help(math.sin)
Help on built-in function sin in module math:sin(...)sin(x)Return the sine of x (measured in radians).

查看函数信息的另一种方法print(func_name.doc)

>>> print(print.__doc__)
print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)Prints the values to a stream, or to sys.stdout by default.
Optional keyword arguments:
file:  a file-like object (stream); defaults to the current sys.stdout.
sep:   string inserted between values, default a space.
end:   string appended after the last value, default a newline.
flush: whether to forcibly flush the stream.

__doc__前后是两个下划线, 在Python中会合并为长下划线

Python帮助文档的使用相关推荐

  1. python 帮助文档、自我解释

    现在让我们以交互方式使用 Python 来开始研究.当我们从命令行启动 Python 时,就进入了 Python shell,在这里可以输入 Python 代码,而且立刻会从 Python 解释器获得 ...

  2. python 帮助文档,撰写函数文档,并查看函数文档

    python 帮助文档,撰写函数文档,并查看函数文档 定义函数 def test(a,b):'''参数:a:整数b:整数返回值:a+b'''return a+b 运行函数 test(11,22) 33 ...

  3. 关于深度学习框架Hamaa与Python API文档生成工具Sophon

    五月两场 | NVIDIA DLI 深度学习入门课程 5月19日/5月26日一天密集式学习  快速带你入门阅读全文> 正文共1988个字,预计阅读时间12分钟. 前言 最近三个月我主要花时间在造 ...

  4. Python之文档测试

    0 参考文档 Sphinx--自动生成Python文档 Python之文档测试模块--doctest 1 doctest doctest是python自带的一个模块.doctest有两种使用方式:一种 ...

  5. Python处理文档

    本文转载自:https://blog.csdn.net/fudaxing/article/details/88736916 Python处理文档Python可以创建和修改具有.docx文件的Word文 ...

  6. python创建文档

    python创建文档 创建word文档 首先我们要安装会用到的三方库 在终端输入以下代码安装 pip install python-docx pillow 这里我们制作的word文档会涉及到图,我们将 ...

  7. sphinx:基于 Python 的文档生成工具

    sphinx:基于 Python 的文档生成工具 Motivation 对于软件开发来说,文档是软件可维护性的重要保障.sphinx 是一款文档生成工具,以 restructuredText 为标记语 ...

  8. Python 操作文档之请假条

    Python 操作文档之请假条.md from docx import Document from datetime import datetimedoc=Document() doc.add_hea ...

  9. python生成接口文档_使用apiDoc实现python接口文档编写

    使用apiDoc实现python接口文档编写 apiDoc的安装 npm install apidoc -g 生成api的终端命令:apidoc -i 代码所在路径-o 生成文件的路径 接口文档的编写 ...

  10. python api 文档查看方式

    1. cmd命令: python -m pydoc -p 1234 然后按照提示访问指定网址: 2. 浏览器访问http://localhost:1234就可查看全部的Python api文档: 3. ...

最新文章

  1. Py中re.sub学习【转载】
  2. Vue.js(一) Vue.js + element-ui 扫盲
  3. java imageio删除图片_Java 提取、替换、删除PDF文档中的图片
  4. hdu 5256 序列变换 (LIS变形)
  5. python模块导入_Python模块及其导入
  6. Qt:Qt实现飞秋拦截助手—Mac地址扫描器
  7. CSS 布局经典问题初步整理
  8. TransactionScope和分布式事务的注意点
  9. Jenkins学习三:介绍一些Jenkins的常用功能
  10. 基于虚拟日志压缩的数据同步方案
  11. python 类方法 静态方法_Python静态方法和类方法
  12. 陶教授,我记不住定理的证明该怎么办?(我看到陶哲轩在博客上与学生一则有意思的互动,就翻译过来了)...
  13. RE文件管理器如何获取小程序APKG文件
  14. 微信小程序Code获取
  15. 计算机保存文件快捷键,保存快捷键是什么,保存文档的快捷键
  16. Oracle中国区大裁员:昔日辉煌不再,退出中国市场?
  17. 06-图3 六度空间 (30分)
  18. SpringBoot线程池实现200w数据快速落库
  19. Mac配置Qt环境和把应用打包成dmg文件
  20. (郭霖)Android图片加载框架最全解析(一),Glide的基本用法

热门文章

  1. 1.python-web
  2. Git 右键不显示Git功能图标
  3. 概率分布,独立同分布在图像分类与检测中到底代表什么?
  4. 经验模态分解与Python调用实例
  5. 【每日论文】GenCo: Generative Co-training for Generative Adversarial Networks with Limited Data
  6. 用Python写的随机起名字的程序(可以起两字或三字名字)
  7. VS Code + phpstudy实现PHP环境配置
  8. 从应用角度了解下LIN总线
  9. mysql中TINYINT的取值范围
  10. 轩小陌的Python笔记-day14 自定义模块、第三方模块、内置模块(部分)