python的help函数如何使用

python的help函数如何使用

更多python视频教程请到菜鸟教程https://www.piaodoo.com/

help函数是python的一个内置函数,在python基础知识中介绍过什么是内置函数,它是python自带的函数,任何时候都可以被使。help函数能作什么、怎么使用help函数查看python模块学习中函数的用法,和使用help函数时需要注意哪些问题,下面来简单的说一下。

help函数能作什么

在使用python来编写代码时,会经常使用python调用函数、自带函数或模块,一些不常用的函数或是模块的用途不是很清楚,这时候就需要用到help函数来查看帮助。

这里要注意下,help()函数是查看函数或模块用途的详细说明,而dir()函数是查看函数或模块内的操作方法都有什么,输出的是方法列表。

怎么使用help函数查看python模块中函数的用法

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

使用help函数查看帮助时需要注意哪些问题

在写help()函数使用方法时说过,括号中填写参数,那在这里要注意参数的形式:

1、查看一个模块的帮助

>>>help('sys')

之后它回打开这个模块的帮助文档

2、查看一个数据类型的帮助

>>>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的help函数如何使用的文章就介绍到这了,更多相关如何使用python的help函数内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多

茂名论坛https://www.hnthzk.com/

化州橘红http://www.sfkyty.com/

茂名论坛http://www.nrso.net/

源码搜藏网http://www.cntkd.net/

  • 9
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值