【学习Python】Python查看帮助---help函数
2018-01-21 19:49
239 查看
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所有的modules:help("modules")
单看python所有的modules中包含指定字符串的modules: help("modules yourstr")
查看python中常见的topics: help("topics")
查看python标准库中的module:import os.path + help("os.path")
查看python内置的类型:help("list")
查看python类型的成员方法:help("str.find")
查看python内置函数:help("open")
查看所有的关键字:help("keywords")
查看所有的modules:help("modules")
单看所有的modules中包含指定字符串的modules: help("modules yourstr")
查看中常见的topics: help("topics")
查看标准库中的module:import os.path + help("os.path")
查看内置的类型:help("list")
查看类型的成员方法:help("str.find")
查看内置函数:help("open")
help() 函数用于查看函数或模块用途的详细说明。
help 语法:
参数说明:
object -- 对象;
返回对象帮助信息。
以下实例展示了 help 的使用方法:
>>>help('sys')#
查看 sys 模块的帮助……显示帮助信息……
>>>help('str')#
查看 str 数据类型的帮助……显示帮助信息……
>>>a
= [1,2,3]>>>help(a)#
查看列表 list 帮助信息……显示帮助信息……
>>>help(a.append)#
显示list的append方法的帮助……显示帮助信息……
一、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下 help()使用方法
查看python所有的modules:help("modules")单看python所有的modules中包含指定字符串的modules: help("modules yourstr")
查看python中常见的topics: help("topics")
查看python标准库中的module:import os.path + help("os.path")
查看python内置的类型:help("list")
查看python类型的成员方法:help("str.find")
查看python内置函数:help("open")
查看所有的关键字:help("keywords")
查看所有的modules:help("modules")
单看所有的modules中包含指定字符串的modules: help("modules yourstr")
查看中常见的topics: help("topics")
>>> help("topics") Here is a list of available topics. Enter any topic name to get more help. ASSERTION DEBUGGING LITERALS SEQUENCEMETHODS2 ASSIGNMENT DELETION LOOPING SEQUENCES ATTRIBUTEMETHODS DICTIONARIES MAPPINGMETHODS SHIFTING ATTRIBUTES DICTIONARYLITERALS MAPPINGS SLICINGS AUGMENTEDASSIGNMENT DYNAMICFEATURES METHODS SPECIALATTRIBUTES BACKQUOTES ELLIPSIS MODULES SPECIALIDENTIFIERS BASICMETHODS EXCEPTIONS NAMESPACES SPECIALMETHODS BINARY EXECUTION NONE STRINGMETHODS BITWISE EXPRESSIONS NUMBERMETHODS STRINGS BOOLEAN FILES NUMBERS SUBSCRIPTS CALLABLEMETHODS FLOAT OBJECTS TRACEBACKS CALLS FORMATTING OPERATORS TRUTHVALUE CLASSES FRAMEOBJECTS PACKAGES TUPLELITERALS CODEOBJECTS FRAMES POWER TUPLES COERCIONS FUNCTIONS PRECEDENCE TYPEOBJECTS COMPARISON IDENTIFIERS PRINTING TYPES COMPLEX IMPORTING PRIVATENAMES UNARY CONDITIONAL INTEGER RETURNING UNICODE CONTEXTMANAGERS LISTLITERALS SCOPING CONVERSIONS LISTS SEQUENCEMETHODS1例如想要查看CALLS主题的帮助,则:help("CALLS")
查看标准库中的module:import os.path + help("os.path")
查看内置的类型:help("list")
查看类型的成员方法:help("str.find")
查看内置函数:help("open")
描述
help() 函数用于查看函数或模块用途的详细说明。
语法
help 语法:help([object])
参数说明:
object -- 对象;
返回值
返回对象帮助信息。
实例
以下实例展示了 help 的使用方法:>>>help('sys')#
查看 sys 模块的帮助……显示帮助信息……
>>>help('str')#
查看 str 数据类型的帮助……显示帮助信息……
>>>a
= [1,2,3]>>>help(a)#
查看列表 list 帮助信息……显示帮助信息……
>>>help(a.append)#
显示list的append方法的帮助……显示帮助信息……
相关文章推荐
- python学习-Day7-python帮助查看及数据类型转换
- Python查看帮助---help函数
- Python查看帮助---help函数
- Python查看帮助---help函数
- 如何充分利用python的帮助查看
- 【学习笔记】启动Nginx、查看nginx进程、查看nginx服务主进程的方式、Nginx服务可接受的信号、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
- python2学习笔记之查看API接口、http的使用
- caffe的python接口学习(12):查看属性、方法以及函数参数
- python在命令行模式下查看帮助文档
- 【学习笔记】启动Nginx、查看nginx进程、查看nginx服务主进程的方式、Nginx服务可接受的信号、nginx帮助命令、Nginx平滑重启、Nginx服务器的升级
- Python帮助文档的查看
- win10 python 查看安装库的帮助文档
- python圣斗士修炼(六):查看python帮助和学会数据类型转换
- 查看python的帮助及变量类型的强制转换
- python基础31[help()来查看帮助]
- python中os模块中文帮助--收藏,以后学习
- Linux下面查看python帮助文档
- Python源码学习 番外-为方便调试和查看变量而自己写的autoexp.dat
- 在命令行模式下查看Python帮助文档---dir、help、__doc__
- Python 查看帮助文档 dir(),help()