Python help()函数用法详解


Posted in Python onMarch 11, 2014

help函数是python的一个内置函数(python的内置函数可以直接调用,无需import),它是python自带的函数,任何时候都可以被使用。help函数能作什么、怎么使用help函数查看python模块中函数的用法,和使用help函数时需要注意哪些问题,下面来简单的说一下。

一、help()函数的作用
在使用python来编写代码时,会经常使用python自带函数或模块,一些不常用的函数或是模块的用途不是很清楚,这时候就需要用到help函数来查看帮助。
这里要注意下,help()函数是查看函数或模块用途的详细说明,而dir()函数是查看函数或模块内的操作方法都有什么,输出的是方法列表。
二、怎么使用help函数查看python模块中函数的用法
help()括号内填写参数,操作方法很简单。例如:

>>> help('dir')
Help on built-in function dir in module builtins:
dir(...)
    dir([object]) -> list of strings
    If called without an argument, return the names in the current scope.
    Else, return an alphabetized list of names comprising (some of) the attribut
es
    of the given object, and of attributes reachable from it.
    If the object supplies a method named __dir__, it will be used; otherwise
    the default dir() logic is used and returns:
      for a module object: the module's attributes.
      for a class object:  its attributes, and recursively the attributes
        of its bases.
      for any other object: its attributes, its class's attributes, and
        recursively the attributes of its class's base classes.

三、使用help函数查看帮助实例

在写help()函数使用方法时说过,括号中填写参数,那在这里要注意参数的形式:

1、查看一个模块的帮助

>>>help('sys')

之后它回打开这个模块的帮助文档
2、查看一个数据类型的帮助
>>>help('str')

返回字符串的方法及详细说明
>>>a = [1,2,3]
>>>help(a)

这时help(a)则会打开list的操作方法
>>>help(a.append)

会显示list的append方法的帮助
Python 相关文章推荐
python如何对实例属性进行类型检查
Mar 20 Python
python email smtplib模块发送邮件代码实例
Apr 26 Python
django 发送邮件和缓存的实现代码
Jul 18 Python
使用Python实现图像标记点的坐标输出功能
Aug 14 Python
手写一个python迭代器过程详解
Aug 27 Python
flask框架json数据的拿取和返回操作示例
Nov 28 Python
Python递归及尾递归优化操作实例分析
Feb 01 Python
Python基础之字符串常见操作经典实例详解
Feb 26 Python
浅谈Python中os模块及shutil模块的常规操作
Apr 03 Python
使用jupyter notebook将文件保存为Markdown,HTML等文件格式
Apr 14 Python
神经网络训练采用gpu设置的方式
Mar 03 Python
Python实现仓库管理系统
May 30 Python
python操作日期和时间的方法
Mar 11 #Python
Python 字符串操作方法大全
Mar 11 #Python
Python去掉字符串中空格的方法
Mar 11 #Python
使用python 获取进程pid号的方法
Mar 10 #Python
python调用java的Webservice示例
Mar 10 #Python
pyqt4教程之messagebox使用示例分享
Mar 07 #Python
pyqt4教程之widget使用示例分享
Mar 07 #Python
You might like
一段实用的php验证码函数
2016/05/19 PHP
PHP针对伪静态的注入总结【附asp与Python相关代码】
2017/08/01 PHP
最简单的jQuery程序 入门者学习
2009/07/09 Javascript
Angularjs过滤器使用详解
2016/05/25 Javascript
AngularJS中的包含详细介绍及实现示例
2016/07/28 Javascript
详解微信小程序 页面跳转 传递参数
2016/12/08 Javascript
Angular使用$http.jsonp发送跨站请求的方法
2017/03/16 Javascript
前端图片懒加载(lazyload)的实现方法(提高用户体验)
2017/08/21 Javascript
cdn模式下vue的基本用法详解
2018/10/07 Javascript
three.js实现圆柱体
2018/12/30 Javascript
JavaScript函数式编程(Functional Programming)纯函数用法分析
2019/05/22 Javascript
在layui中对table中的数据进行判断(0、1)转换为提示信息的方法
2019/09/28 Javascript
构建大型 Vue.js 项目的10条建议(小结)
2019/11/14 Javascript
解决vue单页面应用打包后相对路径、绝对路径相关问题
2020/08/14 Javascript
nodejs+koa2 实现模仿springMVC框架
2020/10/21 NodeJs
[41:56]Spirit vs Liquid Supermajor小组赛A组 BO3 第一场 6.2
2018/06/03 DOTA
Python写的服务监控程序实例
2015/01/31 Python
python递归计算N!的方法
2015/05/05 Python
Python中if __name__ == '__main__'作用解析
2015/06/29 Python
浅述python中argsort()函数的实例用法
2017/03/30 Python
windows下python连接oracle数据库
2017/06/07 Python
Python查询IP地址归属完整代码
2017/06/21 Python
在pycharm中python切换解释器失败的解决方法
2018/10/29 Python
Python + selenium + requests实现12306全自动抢票及验证码破解加自动点击功能
2018/11/23 Python
Python 编程速成(推荐)
2019/04/15 Python
Python3批量生成带logo的二维码方法
2019/06/24 Python
python模块和包的应用BASE_PATH使用解析
2019/12/14 Python
为你的html5网页添加音效示例
2014/04/03 HTML / CSS
中东地区最大的奢侈品市场:The Luxury Closet
2019/04/09 全球购物
Hotels.com日本:国外和海外住宿,酒店预订
2019/12/13 全球购物
文明青少年标兵事迹材料
2014/01/28 职场文书
绿色环保演讲稿
2014/05/10 职场文书
不同意离婚上诉状
2015/05/23 职场文书
您对思维方式了解多少?
2019/12/09 职场文书
浅谈Python 中的复数问题
2021/05/19 Python
NASA 机智号火星直升机拍到了毅力号设备碎片
2022/04/29 数码科技