像'_doc_'这样的函数和append这样的函数有啥区别?(注:这两个函数是列表能使用的系统函数)

img


(此处占位
像'doc'这样的函数和append这样的函数有啥区别?(注:这两个函数是列表能使用的系统函数)

双下划线开头的函数是类的保留方法,append()是普通方法。

__doc__,基本上所有类里都有的:

>>> [].__doc__
'Built-in mutable sequence.\n\nIf no argument is given, the constructor creates a new empty list.\nThe argument must be an iterable if specified.'
>>> print([].__doc__)
Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list.
The argument must be an iterable if specified.

>>> print(''.__doc__)
str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.

>>> print(int(123).__doc__)
int([x]) -> integer
int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments
are given.  If x is a number, return x.__int__().  For floating point
numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base.  The literal can be preceded by '+' or '-' and be surrounded
by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4

就是一个函数的简介文档,你也可以自定义一个:

>>> def abc():
    '''
    这是函数简单介绍
    .......
    .......
    '''
    pass

>>> abc.__doc__
'\n\t这是函数简单介绍\n\t.......\n\t.......\n\t'
>>>