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利用elaphe制作二维条形码实现代码
May 25 Python
Python的“二维”字典 (two-dimension dictionary)定义与实现方法
Apr 27 Python
Python 两个列表的差集、并集和交集实现代码
Sep 21 Python
在Python web中实现验证码图片代码分享
Nov 09 Python
Python切片索引用法示例
May 15 Python
pycharm安装和首次使用教程
Aug 27 Python
一百多行python代码实现抢票助手
Sep 25 Python
Python 利用scrapy爬虫通过短短50行代码下载整站短视频
Oct 29 Python
Python Cookie 读取和保存方法
Dec 28 Python
解决python中用matplotlib画多幅图时出现图形部分重叠的问题
Jul 07 Python
python写一个随机点名软件的实例
Nov 28 Python
基于Python执行dos命令并获取输出的结果
Dec 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
mysql_connect localhost和127.0.0.1的区别(网络层阐述)
2015/03/26 PHP
PHP实现通过URL提取根域名
2016/03/31 PHP
PHP中include和require的区别实例分析
2017/05/07 PHP
jQuery 剧场版 你必须知道的javascript
2009/05/27 Javascript
告诉你什么是javascript的回调函数
2014/09/04 Javascript
requireJS模块化实现返回顶部功能的方法详解
2017/10/16 Javascript
vue-cli 组件的导入与使用教程详解
2018/04/11 Javascript
jQuery实现为动态添加的元素绑定事件实例分析
2018/09/07 jQuery
记一次webapck4 配置文件无效的解决历程
2018/09/19 Javascript
vue自定义指令实现方法详解
2019/02/11 Javascript
基于elementUI使用v-model实现经纬度输入的vue组件
2019/05/12 Javascript
[01:01:52]DOTA2-DPC中国联赛正赛 iG vs LBZS BO3 第一场 3月4日
2021/03/11 DOTA
在Python中使用PIL模块处理图像的教程
2015/04/29 Python
Python递归函数定义与用法示例
2017/06/02 Python
python 计算数组中每个数字出现多少次--“Bucket”桶的思想
2017/12/19 Python
Python中生成器和迭代器的区别详解
2018/02/10 Python
不管你的Python报什么错,用这个模块就能正常运行
2018/09/14 Python
Python单元测试unittest的具体使用示例
2018/12/17 Python
python 实现矩阵上下/左右翻转,转置的示例
2019/01/23 Python
Python下简易的单例模式详解
2019/04/08 Python
解决django后台管理界面添加中文内容乱码问题
2019/11/15 Python
Pytorch根据layers的name冻结训练方式
2020/01/06 Python
Matplotlib使用字符串代替变量绘制散点图的方法
2020/02/17 Python
Python日志:自定义输出字段 json格式输出方式
2020/04/27 Python
Python实现将元组中的元素作为参数传入函数的操作
2020/06/05 Python
使用Python绘制台风轨迹图的示例代码
2020/09/21 Python
UNIONBAY官网:美国青少年服装品牌
2019/03/26 全球购物
几个Shell Script面试题
2014/04/18 面试题
给儿子的表扬信
2014/01/15 职场文书
党员干部公开承诺书
2014/03/26 职场文书
审计局班子四风对照检查材料思想汇报
2014/10/07 职场文书
先进员工事迹材料
2014/12/20 职场文书
一文搞懂Redis中String数据类型
2022/04/03 Redis
使用Python解决图表与画布的间距问题
2022/04/11 Python
SQL Server使用PIVOT与unPIVOT实现行列转换
2022/05/25 SQL Server