【问题标题】:Understanding Python help() 's ... syntax, and the pop function for dictionaries理解 Python help() 的 ... 语法和字典的 pop 函数
【发布时间】:2021-02-05 00:48:55
【问题描述】:

各种python“帮助”方法/函数描述旁边的...似乎没有在任何地方定义。在 python help 输出描述的上下文中,function(...) 是什么意思?

具体来说,python的pop函数的文档应该如何解释?

详情

鉴于pop 需要输入,help({}) 没有在函数输入描述 (...) 中显示这一点有点令人困惑。 将... 解释为“同上”是行不通的——例如,“items”不能接受任何输入。

要清楚,这是来自help 的函数输入定义。

pop(...)

help({}) 函数的完整输出,get...pop 如下。 ... 的含义是什么,为什么没有为 pop 函数定义输入?

     |  get(self, key, default=None, /)
     |      Return the value for key if key is in the dictionary, else default.
     |  
     |  items(...)
     |      D.items() -> a set-like object providing a view on D's items
     |  
     |  keys(...)
     |      D.keys() -> a set-like object providing a view on D's keys
     |  
     |  pop(...)
     |      D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
     |      If key is not found, d is returned if given, otherwise KeyError is raised

【问题讨论】:

    标签: python function methods documentation


    【解决方案1】:
    languages = ['Python', 'Java', 'C++', 'Ruby', 'C']
    # here is a list
    languages.pop(2)
    # this will call the pop function for
    # languages list and the it removes the element
    # at the specified position.
    # so after you take a look at languages
    languages
    
    Output: ['Python', 'Java', 'Ruby', 'C']
    

    至于你的问题。 “pop”是一个函数,所以它的用法和其他函数一样

    thelist.pop(你想要移除的元素)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-26
      • 1970-01-01
      • 2011-01-26
      • 1970-01-01
      • 2015-03-22
      • 2022-06-14
      • 1970-01-01
      • 2021-03-12
      相关资源
      最近更新 更多