声明:在人工智能技术教学期间,不少学生向我提一些python相关的问题,所以为了让同学们掌握更多扩展知识更好地理解AI技术,我让助理负责分享这套python系列教程,希望能帮到大家!由于这套python教程不是由我所写,所以不如我的AI技术教学风趣幽默,学起来比较枯燥;但它的知识点还是讲到位的了,也值得阅读!想要学习AI技术的同学可以点击跳转到我的​​教学网站​​。PS:看不懂本篇文章的同学请先看前面的文章,循序渐进每天学一点就不会觉得难了!

Python配备了一个help函数,使文档字符串更易于显示。help函数会将其格式化成各种类型的排列友好的形式。

>>>import sys

>>>help(sys.getrefcount)

Help on built-in function getrefcount in module sys:




getrefcount(...)

getrefcount(object) -> integer

Return the reference count of object.The count returned is generally

one higher than you might expect,because it includes the (temporary)

...more omitted...

就较大对象而言,诸如,模块和类,help显示内容会分成几段。

>>>help(sys)

Help on built-in module sys:




NAME

sys

FILE

(built-in)

MODULE DOCS

http://docs.python.org/library/sys

DESCRIPTION

This module provides access to some objects used or maintained by the

interpreter and to functions that interact strongly with the interpreter.

...more omitted...

FUNCTIONS

__displayhook__ = displayhook(...)

displayhook(object) -> None

Print an object to sys.stdout and also save it in builtins.

...more omitted...

DATA

__stderr__ = <io.TextIOWrapper object at 0x0236E950>

__stdin__ = <io.TextIOWrapper object at 0x02366550>

__stdout__ = <io.TextIOWrapper object at 0x02366E30>

...more omitted...

你也可以对内置函数、方法以及类型使用help。要取得内置类型的help信息,就使用其类型名称(例如,字典为dict,字符串为str,列表为list)。

>>>help(dict)

Help on class dict in module builtins:




class dict(object)

| dict() -> new empty dictionary.

| dict(mapping) -> new dictionary initialized from a mapping object's

...more omitted...




>>>help(str.replace)

Help on method_descriptor:




replace(...)

S.replace (old,new[,count]) -> str

Return a copy of S with all occurrences of substring

...more omitted...

>>>help(ord)

Help on built-in function ord in module builtins:




ord(...)

ord(c) -> integer

Return the integer ordinal of a one-character string.

最后,help函数也能用在模块上,就像内置工具一样。

>>>import docstrings

>>>help(docstrings.square)

Help on function square in module docstrings:




square(x)

function documentation

can we have your liver then?




>>>help(docstrings.Employee)

Help on class Employee in module docstrings:

class Employee(builtins.object)

| class documentation

|

| Data descriptors defined here:

...more omitted...




>>>help(docstrings)

Help on module docstrings:




NAME

docstrings

FILE

c:\misc\docstrings.py




DESCRIPTION

Module documentation

Words Go Here




CLASSES

builtins.object

Employee

class Employee(builtins.object)

| class documentation

|

| Data descriptors defined here:

...more omitted...

FUNCTIONS

square(x)

function documentation

can we have your liver then?

DATA

spam = 40