What does pop mean in python?

藏色散人
Release: 2019-06-25 09:21:06
Original
9601 people have browsed it

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)
Copy after login

Output result:

['hello', 'dlrb']
hello
Copy after login

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)
Copy after login

Output results:

{'name': 'dlrb', 'height': 168}
25
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template