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的*args和**kwargs用法
Nov 01 Python
Python实现的简单hangman游戏实例
Jun 28 Python
深入解析Python中的descriptor描述器的作用及用法
Jun 27 Python
Python基于Socket实现的简单聊天程序示例
Aug 05 Python
python实现决策树ID3算法的示例代码
May 30 Python
python使用matplotlib画饼状图
Sep 25 Python
Python查找文件中包含中文的行方法
Dec 19 Python
python中时间、日期、时间戳的转换的实现方法
Jul 06 Python
python导入不同目录下的自定义模块过程解析
Nov 18 Python
布隆过滤器的概述及Python实现方法
Dec 08 Python
在Django中使用MQTT的方法
May 10 Python
python实现双向链表原理
May 25 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
农民和部队如何穿矿
2020/03/04 星际争霸
查找php配置文件php.ini所在路径的二种方法
2014/05/26 PHP
Linux下PHP安装mcrypt扩展模块笔记
2014/09/10 PHP
PHP中的Streams详细介绍
2014/11/12 PHP
php实现改变图片直接打开为下载的方法
2015/04/14 PHP
php简单socket服务器客户端代码实例
2015/05/18 PHP
YII Framework框架教程之缓存用法详解
2016/03/14 PHP
浅谈mysql_query()函数的返回值问题
2016/09/05 PHP
php版微信公众账号第三方管理工具开发简明教程
2016/09/23 PHP
php 运算符与表达式详细介绍
2016/11/30 PHP
Javascript 对象的解释
2008/11/24 Javascript
jQuery循环滚动展示代码 可应用到文字和图片上
2012/05/11 Javascript
关于JavaScript数组你所不知道的3件事
2016/08/24 Javascript
如何用js判断dom是否有存在某class的值
2017/02/13 Javascript
JS使用正则表达式验证身份证号码
2017/06/23 Javascript
详解Webpack DLL用法以及功能
2017/07/11 Javascript
Vue数据监听方法watch的使用
2018/03/28 Javascript
ajax跨域访问遇到的问题及解决方案
2019/05/23 Javascript
Vue.js组件实现选项卡以及切换特效
2019/07/24 Javascript
微信小程序实现手势滑动卡片效果
2019/08/26 Javascript
layui 点击重置按钮, select 并没有被重置的解决方法
2019/09/03 Javascript
vue实现在v-html的html字符串中绑定事件
2019/10/28 Javascript
JS实现秒杀倒计时特效
2020/01/02 Javascript
JavaScript array常用方法代码实例详解
2020/09/02 Javascript
Python Tkinter简单布局实例教程
2014/09/03 Python
Python序列之list和tuple常用方法以及注意事项
2015/01/09 Python
在Python的Django框架中加载模版的方法
2015/07/16 Python
Python调用C++程序的方法详解
2017/01/24 Python
Python查找文件中包含中文的行方法
2018/12/19 Python
对python捕获ctrl+c手工中断程序的两种方法详解
2018/12/26 Python
Python Pandas数据中对时间的操作
2019/07/30 Python
成功的酒店创业计划书
2013/12/27 职场文书
小学生环保倡议书
2014/05/15 职场文书
2014最新党员违纪检讨书
2014/10/12 职场文书
整改通知书格式
2015/04/22 职场文书
Apache Pulsar结合Hudi构建Lakehouse方案分析
2022/03/31 Servers