Immortality207 2022-07-02 16:32 采纳率: 0%
浏览 9

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

img


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

  • 写回答

1条回答 默认 最新

  • Hann Yang 全栈领域优质创作者 2022-07-02 18:51
    关注

    双下划线开头的函数是类的保留方法,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'
    >>> 
    
    评论

报告相同问题?

问题事件

  • 创建了问题 7月2日

悬赏问题

  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥50 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大
  • ¥15 使用spss做psm(倾向性评分匹配)遇到问题
  • ¥20 vue+UEditor附件上传问题
  • ¥15 想做个WPS的自动化代码,不知道能做的起不。
  • ¥15 uniApp,生成安卓安卓包后,黑暗主题中间内容不生效,底部导航正常
  • ¥15 斯坦福自动漂移非线性模型反解