如何解决理解 Python help() 的 ... 语法,以及字典的 pop 函数
各种python“帮助”方法/函数描述旁边的...
似乎没有在任何地方定义。在 python function(...)
输出描述的上下文中,help
是什么意思?
具体来说,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
解决方法
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','C']
至于你的问题。 “pop”是一个函数,所以它的用法和其他函数一样
thelist.pop(the-element-you-want-to-be-removed)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。