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!