Python help()函数用法详解

时间:2022-09-15 13:15:34 

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函数,help
0
投稿

猜你喜欢

  • asp代码WinHttp.WinHttpRequest.5.1使用例子

    2010-03-11 21:28:00
  • Python中的re正则表达式模块

    2022-09-13 15:07:40
  • PaddleOCR 识别表情包文字示例详解

    2023-06-02 06:41:55
  • Php+SqlServer实现分页显示

    2023-11-20 05:02:24
  • oracle下一条SQL语句的优化过程(比较详细)

    2010-04-22 16:58:00
  • Python使用爬虫抓取美女图片并保存到本地的方法【测试可用】

    2023-11-04 19:44:17
  • 10个Python小技巧你值得拥有

    2022-02-03 16:28:56
  • Python更换pip源方法过程解析

    2022-01-20 08:00:58
  • PHP的PDO连接讲解

    2023-06-12 20:40:33
  • 浅谈Python使用Bottle来提供一个简单的web服务

    2021-08-30 13:03:19
  • Python数据类型--字典dictionary

    2023-06-19 12:49:53
  • 简单理解Python中的装饰器

    2021-06-18 01:44:21
  • 解析CSS列表样式属性list-style

    2009-03-26 13:16:00
  • Python实现中一次读取多个值的方法

    2023-01-13 15:55:35
  • python3 实现自定义切片类为左闭右闭详情

    2022-11-02 11:36:51
  • 匿名函数的写法

    2010-01-06 13:32:00
  • Python关键字及可变参数*args,**kw原理解析

    2023-08-25 06:41:47
  • 关于SQL Server数据库备份和恢复特性介绍

    2009-02-19 16:57:00
  • Python使用requests模块爬取百度翻译

    2023-07-31 14:17:22
  • Golang实现文件传输功能

    2023-08-05 13:50:31
  • asp之家 网络编程 m.aspxhome.com