1.函数名及其来源
help 源于英文,标识帮助
help函数是python的一个内置函数(python的内置函数可以直接调用,无需import)
所以我们执行help示例:
>>>help(sys)
>>> help('sys') # 函数名需用引号包裹
Help on built-in module sys:
NAME
sys
MODULE REFERENCE
https://docs.python.org/3.6/library/sys
The following documentation is automatically generated from the Python
source files. It may be incomplete, incorrect or include features that
are considered implementation detail and may vary between Python
implementations. When in doubt, consult the module reference at the
location listed above.
DESCRIPTION
This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the inte
2.函数定义源码及其用法拆解
一些不常用的函数或是模块的用途不是很清楚,这时候就需要用到help函数来查看帮助。
help([object])
参数说明:
- object: 对象
>>>help('print') #直接传入函数名加引号
也可传入一个数据结构查询帮助方法
如下,就可以展示出可以对list做的操作
>>> a = [1,2,3,4,5]
>>> help(a)
Help on list object:
class list(object)
| list() -> new empty list
| list(iterable) -> new list initialized from iterable's items
|
| Methods defined here:
|
| __add__(self, value, /)
| Return self+value.
|
| __contains__(self, key, /)
还可以具体到某个方法:
>>>a =[1,2,3,4,5]
>>>help(a.append)
Help on built-in function append:
append(...) method of builtins.list instance
L.append(object) -> None -- append object to end
3.版本差异
无版本差异
4.学习建议
当手边资料较少时,不要忘了系统提供的help函数可以提供给我们陌生方法的用法参考。
对基础运行环境有疑问的,推荐参考:python函数深入浅出 0.基础篇