Python help()函数用法详解

yipeiwu_com5年前Python基础

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编写一个验证码图片数据标注GUI程序附源码

Python编写一个验证码图片数据标注GUI程序附源码

做验证码图片的识别,不论是使用传统的ORC技术,还是使用统计机器学习或者是使用深度学习神经网络,都少不了从网络上采集大量相关的验证码图片做数据集样本来进行训练。 采集验证码图片,可以直接...

对命令行模式与python交互模式介绍

命令行模式与python交互模式 1.在命令行模式下,可以执行 python 进入 Python 交互式环境,也可以执 行 python hello.py 运行一个.py 文件。 2.在...

python numpy函数中的linspace创建等差数列详解

python numpy函数中的linspace创建等差数列详解

前言 本文主要给大家介绍的是关于linspace创建等差数列的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 numpy.linspace 是用于创建一个由等...

python开发之函数定义实例分析

本文实例讲述了python开发之函数定义方法。分享给大家供大家参考,具体如下: 下面是我做的几个用列: #python中的函数定义,使用和传参 def_str = '''\ py...

python安装gdal的两种方法

1.不用手动下载文件,直接执行以下命令即可 conda install gdal 2.首先,下载gdal的whl文件  链接, 官网下载比较慢,GDAL-2.2.4-cp27-...