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中使用__slots__方法的详细教程
Apr 28 Python
详解python3百度指数抓取实例
Dec 12 Python
Python的标准模块包json详解
Mar 13 Python
Python3.X 线程中信号量的使用方法示例
Jul 24 Python
python爬虫获取淘宝天猫商品详细参数
Jun 23 Python
详解Python 装饰器执行顺序迷思
Aug 08 Python
Python面向对象进阶学习
May 21 Python
Djang的model创建的字段和参数详解
Jul 27 Python
python 利用turtle库绘制笑脸和哭脸的例子
Nov 23 Python
Python 用__new__方法实现单例的操作
Dec 11 Python
解决pytorch 损失函数中输入输出不匹配的问题
Jun 05 Python
python 字典和列表嵌套用法详解
Jun 29 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 gbk环境下json_dencode传送来的汉字
2012/11/13 PHP
关于file_get_contents返回为空或函数不可用的解决方案
2013/06/24 PHP
php二分查找二种实现示例
2014/03/12 PHP
php_screw安装使用教程(另一个PHP代码加密实现)
2014/05/29 PHP
php使用Jpgraph绘制柱形图的方法
2015/06/10 PHP
给WordPress中的留言加上楼层号的PHP代码实例
2015/12/14 PHP
在laravel中实现事务回滚的方法
2019/10/10 PHP
爆炸式的JS圆形浮动菜单特效代码
2010/03/03 Javascript
基于jquery & json的省市区联动代码
2012/06/26 Javascript
JavaScript中的方法调用详细介绍
2014/12/30 Javascript
jQuery实现Meizu魅族官方网站的导航菜单效果
2015/09/14 Javascript
Bootstrap项目实战之首页内容介绍(全)
2016/04/25 Javascript
Web打印解决方案之证件套打的实现思路
2016/08/29 Javascript
在JavaScript中调用Java类和接口的方法
2016/09/07 Javascript
jQuery实现的简单动态添加、删除表格功能示例
2017/09/21 jQuery
详解基于Vue cli生成的Vue项目的webpack4升级
2018/06/19 Javascript
vue实现中部导航栏布局功能
2019/07/30 Javascript
JS中的算法与数据结构之集合(Set)实例详解
2019/08/20 Javascript
解决vue init webpack 下载依赖卡住不动的问题
2020/11/09 Javascript
[02:51]DOTA2英雄基础教程 风暴之灵
2013/12/23 DOTA
Python内置的HTTP协议服务器SimpleHTTPServer使用指南
2016/03/30 Python
python使用turtle库绘制时钟
2020/03/25 Python
Python初学者需要注意的事项小结(python2与python3)
2018/09/26 Python
详解python中的time和datetime的常用方法
2019/07/08 Python
用python实现英文字母和相应序数转换的方法
2019/09/18 Python
详解pandas绘制矩阵散点图(scatter_matrix)的方法
2020/04/23 Python
python如何写try语句
2020/07/14 Python
python 实现"神经衰弱"翻牌游戏
2020/11/09 Python
Restful_framework视图组件代码实例解析
2020/11/17 Python
荷兰领先的百货商店:De Bijenkorf
2018/10/17 全球购物
类成员函数的重载、覆盖和隐藏区别
2016/01/27 面试题
主治医师岗位职责
2013/12/10 职场文书
大学毕业自我评价
2014/02/02 职场文书
阿里云Nginx配置https实现域名访问项目(图文教程)
2021/03/31 Servers
vue-router中hash模式与history模式的区别
2021/06/23 Vue.js
html5调用摄像头实例代码
2021/06/28 HTML / CSS