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检查字符串是否是正确ISBN的方法
Jul 11 Python
python交互式图形编程实例(三)
Nov 17 Python
Python语言实现将图片转化为html页面
Dec 06 Python
pandas.loc 选取指定列进行操作的实例
May 18 Python
用Django写天气预报查询网站
Oct 21 Python
Python如何使用Gitlab API实现批量的合并分支
Nov 27 Python
python操作gitlab API过程解析
Dec 27 Python
Python实现银行账户资金交易管理系统
Jan 03 Python
python+selenium 简易地疫情信息自动打卡签到功能的实现代码
Aug 22 Python
python如何导出微信公众号文章方法详解
Aug 31 Python
Python将list元素转存为CSV文件的实现
Nov 16 Python
Python打包为exe详细教程
May 18 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
xml在joomla表单中的应用详解分享
2012/07/19 PHP
smarty基础之拼接字符串的详解
2013/06/18 PHP
php中substr()函数参数说明及用法实例
2014/11/15 PHP
php输出xml属性的方法
2015/03/19 PHP
Laravel 5 框架入门(四)完结篇
2015/04/09 PHP
CodeIgniter框架基本增删改查操作示例
2017/03/23 PHP
php生成毫秒时间戳的实例讲解
2017/09/22 PHP
JS实现程序暂停与继续功能代码解读
2013/10/10 Javascript
Javascript基础知识(二)事件
2014/09/29 Javascript
JavaScript程序设计之JS调试
2015/12/09 Javascript
jQuery Validate表单验证插件 添加class属性形式的校验
2016/01/18 Javascript
全面解析Javascript无限添加QQ好友原理
2016/06/15 Javascript
jquery移除了live()、die(),新版事件绑定on()、off()的方法
2016/10/26 Javascript
浅谈js键盘事件全面控制
2016/12/01 Javascript
vue-cli3中vue.config.js配置教程详解
2019/05/29 Javascript
封装微信小程序http拦截器过程解析
2019/08/13 Javascript
详解Vscode中使用Eslint终极配置大全
2019/11/08 Javascript
js实现跳一跳小游戏
2020/07/31 Javascript
基于javascript的无缝滚动动画1
2020/08/07 Javascript
[00:53]2015国际邀请赛 中国区预选赛一触即发
2015/05/14 DOTA
python实现日常记账本小程序
2018/03/10 Python
修改 CentOS 6.x 上默认Python的方法
2019/09/06 Python
英国知名奢侈品包包品牌:Milli Millu
2016/12/22 全球购物
英国伦敦的睡衣品牌:Asceno
2019/10/06 全球购物
Envie de Fraise意大利:法国网上推出的孕妇装品牌
2020/10/18 全球购物
工地安全生产标语
2014/06/06 职场文书
警察群众路线整改措施
2014/09/26 职场文书
2014年仓库管理员工作总结
2014/11/18 职场文书
2014年接待工作总结
2014/11/26 职场文书
实习介绍信模板
2015/01/30 职场文书
2015年公司后勤管理工作总结
2015/05/13 职场文书
阿甘正传观后感
2015/06/01 职场文书
《老人与海鸥》教学反思
2016/02/16 职场文书
2016年社区中秋节活动总结
2016/04/05 职场文书
Redis6.0搭建集群Redis-cluster的方法
2021/05/08 Redis
Go gorilla/sessions库安装使用
2022/08/14 Golang