Python 的 help 函数使用-Python教程

资源魔 31 0

help函数是python的一个内置函数,正在python根底常识中引见过甚么是内置函数,它是python自带的函数,任什么时候候均可以被使。help函数能作甚么、怎样应用help函数查看python模块学习中函数的用法,以及应用help函数时需求留意哪些成绩,上面来简略的说一下。

help函数能作甚么

正在应用python来编写代码时,会常常应用python挪用函数、自带函数或模块,一些没有罕用的函数或是模块的用处没有是很分明,这时候候就需求用到help函数来查看协助。

这里要留意下,help()函数是查看函数或模块用处的具体阐明,而dir()函数是查看函数或模块内的操作办法都有甚么,输入的是办法列表。

怎样应用help函数查看python模块中函数的用法

help( )括号内填写参数,操作办法很简略。

应用help函数查看协助时需求留意哪些成绩

正在写help()函数应用办法时说过,括号中填写参数,那正在这里要留意参数的方式:

一、查看一个模块的协助

>>>help('sys')

之后它回关上这个模块的协助文档

二、查看一个数据类型的协助

>>>help('str')

前往字符串的办法及具体阐明

>>>a = [1,2,3]
>>>help(a)

这时候help(a)则会关上list的操作办法

>>>help(a.append)

会显示list的append办法的协助。

实例扩大:

怎样应用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.

保举教程:《Python教程》

以上就是Python 的 help 函数应用的具体内容,更多请存眷资源魔其它相干文章!

标签: Python python教程 python编程 python使用问题 help函数

抱歉,评论功能暂时关闭!