Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

Understanding Python help() 's ... syntax, and the pop function for dictionaries

The ... next to various python "help" method/function descriptions don't seem to be defined anywhere. What does function(...) mean, in the context of the python help output description?

Specifically, how should the documentation for python's pop function be interpreted?

Details

Given that the pop requires an input, it is a little confusing that help({}) doesn't show this in the functions input description (...). Interpreting the ... as "ditto" doesn't work - for example, "items" cannot take any inputs.

To be clear, this is the functions input definition from help.

pop(...)

The full output of the help({}) function, for get...pop is below. What do the ...'s mean, and, why is there no input defined, for the pop function?

     |  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

question from:https://stackoverflow.com/questions/66056050/understanding-python-help-s-syntax-and-the-pop-function-for-dictionaries

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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']

So as for your question. "pop" is a function so its usage is like any other function

thelist.pop(the-element-you-want-to-be-removed)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...