Home  >  Article  >  Backend Development  >  What does pop mean in python?

What does pop mean in python?

藏色散人
藏色散人Original
2019-06-25 09:21:069417browse

What does pop mean in python?

pop() in python removes the element at the specified position in the list. At the same time, the removed element can be assigned to a variable. If the position parameter is not filled in, the last digit will be deleted by default

pop() deletes the key-value pair specified in the dictionary according to the key, and can assign the deleted value to the variable

For example:

 a = ["hello", "world", "dlrb"]
 b = ["hello", "world", "dlrb"]
 a.pop(1)
 b1 = b.pop(0)
 print(a)
 print(b1)

Output result:

['hello', 'dlrb']
hello

We remove the element at position 1 of list a

Remove the element at position 0 of list b and assign it to variable b1

 b = {
    "name":"dlrb",
     "age":25,
     "height":168
 }
 b1 = b.pop("age")
 print(b)
 print(b1)

Output results:

{'name': 'dlrb', 'height': 168}
25

Related recommendations: "Python Tutorial"

The above is the detailed content of What does pop mean in python?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is value in pythonNext article:What is value in python